Compare commits

..

No commits in common. "d8ed73cb00d160686f5f2583ffa0dabb86c4c68d" and "220aef9d5c9692322b360dff42cf763f43317955" have entirely different histories.

3 changed files with 13 additions and 77 deletions

View file

@ -12,8 +12,7 @@
:target-path "target/%s/" :target-path "target/%s/"
:source-paths ["src/main/cljc" :source-paths ["src/main/cljc"
"src/main/clj"] "src/main/clj"]
:resource-paths ["src/main/resources" :resource-paths ["src/main/resources"]
"project.clj"]
:repositories [["snapshots" :clojars] :repositories [["snapshots" :clojars]
["releases" :clojars]] ["releases" :clojars]]
:deploy-repositories [["snapshots" {:sign-releases false :url "https://clojars.org/repo"}] :deploy-repositories [["snapshots" {:sign-releases false :url "https://clojars.org/repo"}]

View file

@ -4,7 +4,6 @@
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as cs] [clojure.string :as cs]
[clojure.tools.reader.edn :as edn] [clojure.tools.reader.edn :as edn]
[clojure.java.io :as io]
[dda.c4k-common.yaml :as yaml] [dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm] [dda.c4k-common.common :as cm]
[dda.c4k-common.core :as core] [dda.c4k-common.core :as core]
@ -13,20 +12,10 @@
(defn usage [name] (defn usage [name]
(str (str
"usage: "usage:
-v | --version : Shows project version
-h : Shows help
The following options require the use of main-cm instead of main-common
-c | --config : Only generate the config
-a | --auth : Only generate the auth
" name " {your configuraton file} {your authorization file}")) " name " {your configuraton file} {your authorization file}"))
(s/def ::options (s/* #{"-h" (s/def ::options (s/* #{"-h"}))
"-v" "--version"
"-c" "--config"
"-a" "--auth"}))
(s/def ::filename (s/and string? (s/def ::filename (s/and string?
#(not (cs/starts-with? % "-")))) #(not (cs/starts-with? % "-"))))
(s/def ::cmd-args (s/cat :options ::options (s/def ::cmd-args (s/cat :options ::options
@ -39,7 +28,7 @@
(s/explain spec args) (s/explain spec args)
(println (str "Bad commandline arguments\n" (usage name)))) (println (str "Bad commandline arguments\n" (usage name))))
(defn main-cm [name config-spec? auth-spec? config-defaults config-objects auth-objects cmd-args] (defn main-common [name config-spec? auth-spec? config-defaults k8s-objects cmd-args]
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)] (let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
(if (= ::s/invalid parsed-args-cmd) (if (= ::s/invalid parsed-args-cmd)
(invalid-args-msg name ::cmd-args cmd-args) (invalid-args-msg name ::cmd-args cmd-args)
@ -48,40 +37,6 @@
(cond (cond
(some #(= "-h" %) options) (some #(= "-h" %) options)
(println (usage name)) (println (usage name))
(some #(or (= "-v" %) (= "--version" %)) options)
(println (some-> (io/resource "project.clj") slurp edn/read-string (nth 2)))
:else
(let [config-str (slurp config)
auth-str (slurp auth)
config-parse-fn (if (yaml/is-yaml? config) yaml/from-string edn/read-string)
auth-parse-fn (if (yaml/is-yaml? auth) yaml/from-string edn/read-string)
config-edn (config-parse-fn config-str)
auth-edn (auth-parse-fn auth-str)
config-valid? (s/valid? config-spec? config-edn)
auth-valid? (s/valid? auth-spec? auth-edn)
only-config (some #(or (= "-c" %) (= "--config" %)) options)
only-auth (some #(or (= "-a" %) (= "--auth" %)) options)]
(if (and config-valid? auth-valid?)
(println (cm/generate-cm config-edn auth-edn config-defaults config-objects auth-objects only-config only-auth))
(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})))))))))))
(defn ^{:deprecated "6.3.1"} 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 name))
(some #(or (= "-v" %) (= "--version" %)) options)
(println (some-> (io/resource "project.clj") slurp edn/read-string (nth 2)))
:else :else
(let [config-str (slurp config) (let [config-str (slurp config)
auth-str (slurp auth) auth-str (slurp auth)
@ -91,15 +46,15 @@
auth-edn (auth-parse-fn auth-str) auth-edn (auth-parse-fn auth-str)
config-valid? (s/valid? config-spec? config-edn) config-valid? (s/valid? config-spec? config-edn)
auth-valid? (s/valid? auth-spec? auth-edn)] auth-valid? (s/valid? auth-spec? auth-edn)]
(if (and config-valid? auth-valid?) (if (and config-valid? auth-valid?)
(println (cm/generate-common config-edn auth-edn config-defaults k8s-objects)) (println (cm/generate-common config-edn auth-edn config-defaults k8s-objects))
(do (do
(when (not config-valid?) (when (not config-valid?)
(println (println
(expound/expound-str config-spec? config-edn {:print-specs? false}))) (expound/expound-str config-spec? config-edn {:print-specs? false})))
(when (not auth-valid?) (when (not auth-valid?)
(println (println
(expound/expound-str auth-spec? auth-edn {:print-specs? false}))))))))))) (expound/expound-str auth-spec? auth-edn {:print-specs? false})))))))))))
(defn -main [& cmd-args] (defn -main [& cmd-args]
(main-common "c4k-common" (main-common "c4k-common"

View file

@ -50,24 +50,6 @@
(into [] (into []
(apply concat vs))) (apply concat vs)))
(defn generate-cm
[my-config
my-auth
config-defaults
config-objects
auth-objects
only-config
only-auth]
(let [resulting-config (merge config-defaults my-config)
both (not (or only-config only-auth))
res-vec (cond
both (concat-vec (config-objects resulting-config) (auth-objects my-auth))
only-config (config-objects my-config)
only-auth (auth-objects my-auth))]
(cs/join
"\n---\n"
res-vec)))
(defn generate-common (defn generate-common
[my-config [my-config
my-auth my-auth