improve error messages
This commit is contained in:
parent
3dd7083d7b
commit
c564c525f4
2 changed files with 26 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
|||
{:source-paths ["src/main"
|
||||
"src/test"]
|
||||
:dependencies [[orchestra "2018.12.06-2"]]
|
||||
:dependencies [[orchestra "2019.02.06-1"]
|
||||
[expound "0.8.4"]]
|
||||
:builds {:dev {:target :node-library
|
||||
:output-to "target/node-lib.js"
|
||||
:exports {:infra mastodon-bot.core/main}
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
[clojure.spec.test.alpha :as st]
|
||||
[clojure.string :as cs]
|
||||
[orchestra.core :refer-macros [defn-spec]]
|
||||
[expound.alpha :as expound]
|
||||
[mastodon-bot.infra :as infra]
|
||||
[mastodon-bot.transform :as transform]
|
||||
[mastodon-bot.mastodon-api :as masto]
|
||||
[mastodon-bot.twitter-api :as twitter]
|
||||
[mastodon-bot.tumblr-api :as tumblr]))
|
||||
|
||||
(set! s/*explain-out* expound/printer)
|
||||
|
||||
(s/def ::mastodon masto/mastodon-auth?)
|
||||
(s/def ::twitter twitter/twitter-auth?)
|
||||
(s/def ::tumblr tumblr/tumblr-auth?)
|
||||
|
@ -40,9 +43,9 @@
|
|||
[config config?]
|
||||
(:transform config))
|
||||
|
||||
(defn transform! [config-location]
|
||||
(let [config (infra/load-config config-location)
|
||||
mastodon-auth (mastodon-auth config)]
|
||||
(defn-spec transform! any?
|
||||
[config config?]
|
||||
(let [mastodon-auth (mastodon-auth config)]
|
||||
(masto/get-mastodon-timeline
|
||||
mastodon-auth
|
||||
(fn [timeline]
|
||||
|
@ -80,15 +83,8 @@
|
|||
))))
|
||||
)))))
|
||||
|
||||
(defn main [& args]
|
||||
(let [parsed-args (s/conform ::args args)]
|
||||
(if (= ::s/invalid parsed-args)
|
||||
(do (s/explain ::args args)
|
||||
(infra/exit-with-error "Bad commandline arguments"))
|
||||
(let [{:keys [options config-location]} parsed-args]
|
||||
(cond
|
||||
(some #(= "-h" %) options)
|
||||
(print "usage:
|
||||
(def usage
|
||||
"usage:
|
||||
|
||||
node target/mastodon-bot.js [-h] /path/to/config.edn
|
||||
|
||||
|
@ -96,8 +92,22 @@
|
|||
|
||||
npm start [-h] /path/to/config.edn
|
||||
")
|
||||
|
||||
(defn main [& args]
|
||||
(let [parsed-args (s/conform ::args args)]
|
||||
(if (= ::s/invalid parsed-args)
|
||||
(do (s/explain ::args args)
|
||||
(infra/exit-with-error (str "Bad commandline arguments\n" usage)))
|
||||
(let [{:keys [options config-location]} parsed-args]
|
||||
(cond
|
||||
(some #(= "-h" %) options)
|
||||
(print usage)
|
||||
:default
|
||||
(transform! config-location))))))
|
||||
(let [config (infra/load-config config-location)]
|
||||
(when (not (s/valid? config? config))
|
||||
(s/explain config? config)
|
||||
(infra/exit-with-error "Bad configuration"))
|
||||
(transform! config)))))))
|
||||
|
||||
(st/instrument 'mastodon-auth)
|
||||
(st/instrument 'twitter-auth)
|
||||
|
|
Reference in a new issue