generate config

This commit is contained in:
jem 2021-02-26 15:27:52 +01:00
parent a8cbdf108b
commit 3611160388
2 changed files with 28 additions and 8 deletions

View file

@ -2,7 +2,8 @@
"src/main/cljs" "src/main/cljs"
"src/main/resources" "src/main/resources"
"src/test/cljc"] "src/test/cljc"]
:dependencies [[aero "1.1.6"]] :dependencies [[aero "1.1.6"]
[expound "0.8.4"]]
:builds {:test {:target :node-test :builds {:test {:target :node-test
:output-to "target/node-tests.js" :output-to "target/node-tests.js"
:autorun true :autorun true

View file

@ -2,20 +2,39 @@
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as cs] [clojure.string :as cs]
[expound.alpha :as expound]
[dda.k8s-mastodon-bot.yaml :as yaml] [dda.k8s-mastodon-bot.yaml :as yaml]
)) ))
(set! s/*explain-out* expound/printer)
(s/def ::options (s/* #{"-h"})) (s/def ::options (s/* #{"-h"}))
(s/def ::config-location (s/? (s/and string? (s/def ::config map?)
#(not (cs/starts-with? % "-"))))) (s/def ::auth map?)
(s/def ::args (s/cat :options ::options (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] (defn main [& args]
(let [parsed-args (s/conform ::args args)] (let [parsed-args (s/conform ::args args)]
(if (= ::s/invalid parsed-args) (if (= ::s/invalid parsed-args)
(do (s/explain ::args args) (do (s/explain ::args args)
) (print (str "Bad commandline arguments\n" usage)))
(let [{:keys [options config-location]} parsed-args] (let [{:keys [options config auth]} parsed-args]
(yaml/from-string "hallo: welt") (cond
)))) (some #(= "-h" %) options)
(print usage)
:default
(yaml/to-string (generate-config config auth)))))))