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:
parent
220067c980
commit
e5dc170ca5
@ -483,6 +483,9 @@
|
|||||||
(defn build-config [config cli-config secrets]
|
(defn build-config [config cli-config secrets]
|
||||||
(util/deep-merge default-config config cli-config secrets))
|
(util/deep-merge default-config config cli-config secrets))
|
||||||
|
|
||||||
|
|
||||||
|
(def default-config-path "config.yaml")
|
||||||
|
|
||||||
(defn main [& args]
|
(defn main [& args]
|
||||||
(-> commander
|
(-> commander
|
||||||
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
(.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 "--basestation-sqb <path>" "Path to a basestation.sqb database file")
|
||||||
(.option "--tweeting" "Enables tweeting")
|
(.option "--tweeting" "Enables tweeting")
|
||||||
(.option "--no-tweeting" "Do not tweet")
|
(.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")
|
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
|
||||||
(.parse (.-argv js/process)))
|
(.parse (.-argv js/process)))
|
||||||
(let [start-time (current-time)]
|
(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)
|
cli-config (build-config-from-commander commander)
|
||||||
secrets (util/read-config (.-secrets commander))
|
secrets (util/read-config (.-secrets commander))
|
||||||
config (build-config base-config cli-config secrets)
|
config (build-config base-config cli-config secrets)
|
||||||
@ -524,3 +533,10 @@
|
|||||||
(/ (- end-time start-time) 1000)
|
(/ (- end-time start-time) 1000)
|
||||||
(count new-db)
|
(count new-db)
|
||||||
(count potential-circles)))))))
|
(count potential-circles)))))))
|
||||||
|
|
||||||
|
|
||||||
|
;; (.on js/process "unhandledRejection"
|
||||||
|
;; (fn [reason promise]
|
||||||
|
;; (log-error "Error: %s" (.-message reason))
|
||||||
|
;; (println (.-stack reason))
|
||||||
|
;; (.exit js/process 1)))
|
||||||
|
@ -29,10 +29,13 @@
|
|||||||
|
|
||||||
(defn read-config [path]
|
(defn read-config [path]
|
||||||
(log-verbose "Reading config file %s" path)
|
(log-verbose "Reading config file %s" path)
|
||||||
|
(p/try
|
||||||
(p/let [data (read-file path {:encoding "utf-8"})]
|
(p/let [data (read-file path {:encoding "utf-8"})]
|
||||||
(let [config (-> (yaml/safeLoad data)
|
(let [config (-> (yaml/safeLoad data)
|
||||||
(js->clj :keywordize-keys true))]
|
(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
|
;; Fetches a URL. Returns a promise that resolves to the body of the
|
||||||
|
Loading…
Reference in New Issue
Block a user