Added uberjar

This commit is contained in:
Clemens Geibel 2021-03-08 13:56:48 +01:00
parent 76ed6b6e7b
commit de5239bd7a
6 changed files with 44 additions and 26 deletions

1
.gitignore vendored
View file

@ -13,4 +13,5 @@ public/js/
*.iml
.idea/
.lein-repl-history

View file

@ -17,9 +17,7 @@
:profiles {:test {:test-paths ["src/test/cljc"]
:resource-paths ["src/test/resources"]
:dependencies [[dda/data-test "0.1.1"]]}
:uberjar {:source-paths ["src/main/clj"]
:resource-paths ["src/main/resources"]
:aot :all
:uberjar {:aot :all
:main dda.k8s-mastodon-bot.uberjar
:uberjar-name "k8s-mastodon-bot-standalone.jar"
:dependencies [[org.clojure/tools.cli "1.0.194"]

View file

@ -0,0 +1,41 @@
(ns dda.k8s-mastodon-bot.uberjar
(:gen-class)
(:require
[clojure.spec.alpha :as s]
[dda.k8s-mastodon-bot.core :as core]))
(def usage
"usage:
k8s-mastodon-bot '{your configuraton}' '{your authorization}'")
; Checks if a string validates a given spec after the string is transformed to Clojure data structure by clojure.edn/read-string.
(defn spec-string? [spec]
(fn [str]
(s/and
(string? str)
(s/valid? spec (clojure.edn/read-string str)))))
(s/def ::config-map-str (spec-string? ::core/config))
(s/def ::auth-map-str (spec-string? ::core/auth))
(s/def ::cmd-args (s/cat :options ::core/options
:config ::config-map-str
:auth ::config-map-str))
(defn invalid-args-msg [spec args]
(do (s/explain spec args)
(println (str "Bad commandline arguments\n" usage))))
(defn -main [& cmd-args]
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
(if (= ::s/invalid parsed-args-cmd)
(invalid-args-msg ::cmd-args cmd-args)
(let [{:keys [options config auth]} parsed-args-cmd
config-map (clojure.edn/read-string config)
auth-map (clojure.edn/read-string auth)]
(cond
(some #(= "-h" %) options)
(println usage)
:default
(println (core/generate config-map auth-map)))))))

View file

@ -1,22 +0,0 @@
(ns dda.k8s-mastodon-bot.uberjar
(:require
[clojure.spec.alpha :as s]
[dda.k8s-mastodon-bot.core :as core]))
(def usage
"usage:
k8s-mastodon-bot {your configuraton} {your authorization}")
(defn main [& args]
(let [parsed-args (s/conform ::core/args args)]
(if (= ::s/invalid parsed-args)
(do (s/explain ::core/args args)
(print (str "Bad commandline arguments\n" usage)))
(let [{:keys [options config auth]} parsed-args]
(cond
(some #(= "-h" %) options)
(print usage)
:default
(core/generate config auth))))))

View file

@ -6,7 +6,7 @@
[dda.k8s-mastodon-bot.yaml :as yaml]
))
(set! s/*explain-out* expound/printer)
;(set! s/*explain-out* expound/printer)
(s/def ::options (s/* #{"-h"}))
(s/def ::config map?)