generate config
This commit is contained in:
parent
a8cbdf108b
commit
3611160388
2 changed files with 28 additions and 8 deletions
|
@ -2,7 +2,8 @@
|
|||
"src/main/cljs"
|
||||
"src/main/resources"
|
||||
"src/test/cljc"]
|
||||
:dependencies [[aero "1.1.6"]]
|
||||
:dependencies [[aero "1.1.6"]
|
||||
[expound "0.8.4"]]
|
||||
:builds {:test {:target :node-test
|
||||
:output-to "target/node-tests.js"
|
||||
:autorun true
|
||||
|
|
|
@ -2,20 +2,39 @@
|
|||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as cs]
|
||||
[expound.alpha :as expound]
|
||||
[dda.k8s-mastodon-bot.yaml :as yaml]
|
||||
))
|
||||
|
||||
(set! s/*explain-out* expound/printer)
|
||||
|
||||
(s/def ::options (s/* #{"-h"}))
|
||||
(s/def ::config-location (s/? (s/and string?
|
||||
#(not (cs/starts-with? % "-")))))
|
||||
(s/def ::config map?)
|
||||
(s/def ::auth map?)
|
||||
(s/def ::args (s/cat :options ::options
|
||||
:config-location ::config-location))
|
||||
:config ::config
|
||||
:auth ::auth))
|
||||
|
||||
(defn generate-config [my-config my-auth]
|
||||
(->
|
||||
(yaml/from-string (yaml/load-resource "config.yaml"))
|
||||
(assoc-in [:data :config.edn] (str my-config))
|
||||
(assoc-in [ :data :credentials.edn] (str my-auth))
|
||||
))
|
||||
|
||||
(def usage
|
||||
"usage:
|
||||
|
||||
k8s-mastodon-bot {your configuraton} {your authorization}")
|
||||
|
||||
(defn main [& args]
|
||||
(let [parsed-args (s/conform ::args args)]
|
||||
(if (= ::s/invalid parsed-args)
|
||||
(do (s/explain ::args args)
|
||||
)
|
||||
(let [{:keys [options config-location]} parsed-args]
|
||||
(yaml/from-string "hallo: welt")
|
||||
))))
|
||||
(print (str "Bad commandline arguments\n" usage)))
|
||||
(let [{:keys [options config auth]} parsed-args]
|
||||
(cond
|
||||
(some #(= "-h" %) options)
|
||||
(print usage)
|
||||
:default
|
||||
(yaml/to-string (generate-config config auth)))))))
|
||||
|
|
Loading…
Reference in a new issue