Tweaks to config file handling.

If --config config.yaml wasn't specified, don't error out if
config.yaml doesn't exist.
This commit is contained in:
John Wiseman 2020-01-21 17:10:28 -08:00
parent 220067c980
commit e5dc170ca5
2 changed files with 25 additions and 6 deletions

View File

@ -483,6 +483,9 @@
(defn build-config [config cli-config secrets]
(util/deep-merge default-config config cli-config secrets))
(def default-config-path "config.yaml")
(defn main [& args]
(-> commander
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
@ -493,11 +496,17 @@
(.option "--basestation-sqb <path>" "Path to a basestation.sqb database file")
(.option "--tweeting" "Enables tweeting")
(.option "--no-tweeting" "Do not tweet")
(.option "--config <path>" "Path to the configuration yaml file" "config.yaml")
(.option "--config <path>" "Path to the configuration yaml file")
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
(.parse (.-argv js/process)))
(let [start-time (current-time)]
(p/let [base-config (util/read-config (.-config commander))
;; If --config-path is specified, definitely try to read that
;; file. Otherwise, only read config.yaml if it exists.
(p/let [base-config (if-let [config-path (.-config commander)]
(util/read-config config-path)
(if (fs/existsSync default-config-path)
(util/read-config default-config-path)
{}))
cli-config (build-config-from-commander commander)
secrets (util/read-config (.-secrets commander))
config (build-config base-config cli-config secrets)
@ -524,3 +533,10 @@
(/ (- end-time start-time) 1000)
(count new-db)
(count potential-circles)))))))
;; (.on js/process "unhandledRejection"
;; (fn [reason promise]
;; (log-error "Error: %s" (.-message reason))
;; (println (.-stack reason))
;; (.exit js/process 1)))

View File

@ -29,10 +29,13 @@
(defn read-config [path]
(log-verbose "Reading config file %s" path)
(p/try
(p/let [data (read-file path {:encoding "utf-8"})]
(let [config (-> (yaml/safeLoad data)
(js->clj :keywordize-keys true))]
(or config {}))))
(or config {})))
(p/catch :default e
(throw (str "Error reading config file '" path "': " e)))))
;; Fetches a URL. Returns a promise that resolves to the body of the