moved main to uberjar from common ns
This commit is contained in:
parent
56e30b0b5f
commit
2acf9b3bb2
2 changed files with 54 additions and 49 deletions
52
src/main/clj/dda/c4k_common/uberjar.clj
Normal file
52
src/main/clj/dda/c4k_common/uberjar.clj
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
(ns dda.c4k-common.uberjar
|
||||||
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.string :as cs]
|
||||||
|
[clojure.tools.reader.edn :as edn]
|
||||||
|
[dda.c4k-common.common :as cm]
|
||||||
|
[expound.alpha :as expound]))
|
||||||
|
|
||||||
|
(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 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)
|
||||||
|
:else
|
||||||
|
(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 (cm/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})))))))))))
|
|
@ -3,11 +3,9 @@
|
||||||
[clojure.walk]
|
[clojure.walk]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.string :as cs]
|
[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
|
||||||
|
@ -60,53 +58,8 @@
|
||||||
(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]
|
(defn generate-common [my-config my-auth config-defaults k8s-objects]
|
||||||
(let [resulting-config (merge config-defaults my-config my-auth)]
|
(let [resulting-config (merge config-defaults my-config my-auth)]
|
||||||
(cs/join
|
(cs/join
|
||||||
"\n---\n"
|
"\n---\n"
|
||||||
(k8s-objects resulting-config))))
|
(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