Version 1.1.1
This commit is contained in:
parent
bb750ac610
commit
d5cb048221
3 changed files with 57 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-cljs "1.1.1-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-cljs "1.2.0"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-clj "1.1.1-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-clj "1.1.1"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.walk]
|
[clojure.walk]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.string :as cs]
|
||||||
|
[clojure.tools.reader.edn :as edn]
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
[dda.c4k-common.predicate :as cp]))
|
[dda.c4k-common.predicate :as cp]
|
||||||
|
[expound.alpha :as expound]))
|
||||||
|
|
||||||
|
|
||||||
;; deprecated functions were moved to dda.c4k-common.predicate
|
;; deprecated functions were moved to dda.c4k-common.predicate
|
||||||
|
@ -56,3 +59,54 @@
|
||||||
[& vs (s/* seq?)]
|
[& vs (s/* seq?)]
|
||||||
(into []
|
(into []
|
||||||
(apply concat vs)))
|
(apply concat vs)))
|
||||||
|
|
||||||
|
(defn usage [name]
|
||||||
|
(str
|
||||||
|
"usage:
|
||||||
|
|
||||||
|
" name "{your configuraton file} {your authorization file}"))
|
||||||
|
|
||||||
|
(s/def ::options (s/* #{"-h"}))
|
||||||
|
(s/def ::filename (s/and string?
|
||||||
|
#(not (cs/starts-with? % "-"))))
|
||||||
|
(s/def ::cmd-args (s/cat :options ::options
|
||||||
|
:args (s/?
|
||||||
|
(s/cat :config ::filename
|
||||||
|
:auth ::filename))))
|
||||||
|
|
||||||
|
(defn invalid-args-msg
|
||||||
|
[name spec args]
|
||||||
|
(s/explain spec args)
|
||||||
|
(println (str "Bad commandline arguments\n" (usage name))))
|
||||||
|
|
||||||
|
(defn generate-common [my-config my-auth config-defaults k8s-objects]
|
||||||
|
(let [resulting-config (merge config-defaults my-config my-auth)]
|
||||||
|
(cs/join
|
||||||
|
"\n---\n"
|
||||||
|
(k8s-objects resulting-config))))
|
||||||
|
|
||||||
|
(defn main-common [name config-spec? auth-spec? config-defaults k8s-objects cmd-args]
|
||||||
|
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
|
||||||
|
(if (= ::s/invalid parsed-args-cmd)
|
||||||
|
(invalid-args-msg name ::cmd-args cmd-args)
|
||||||
|
(let [{:keys [options args]} parsed-args-cmd
|
||||||
|
{:keys [config auth]} args]
|
||||||
|
(cond
|
||||||
|
(some #(= "-h" %) options)
|
||||||
|
(println usage)
|
||||||
|
:default
|
||||||
|
(let [config-str (slurp config)
|
||||||
|
auth-str (slurp auth)
|
||||||
|
config-edn (edn/read-string config-str)
|
||||||
|
auth-edn (edn/read-string auth-str)
|
||||||
|
config-valid? (s/valid? config-spec? config-edn)
|
||||||
|
auth-valid? (s/valid? auth-spec? auth-edn)]
|
||||||
|
(if (and config-valid? auth-valid?)
|
||||||
|
(println (generate-common config-edn auth-edn config-defaults k8s-objects))
|
||||||
|
(do
|
||||||
|
(when (not config-valid?)
|
||||||
|
(println
|
||||||
|
(expound/expound-str config-spec? config-edn {:print-specs? false})))
|
||||||
|
(when (not auth-valid?)
|
||||||
|
(println
|
||||||
|
(expound/expound-str auth-spec? auth-edn {:print-specs? false})))))))))))
|
||||||
|
|
Loading…
Reference in a new issue