[#479] Add babashka.version system property
This commit is contained in:
parent
475622f7f4
commit
e095e1485a
3 changed files with 23 additions and 3 deletions
|
|
@ -444,14 +444,17 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
(binding [*unrestricted* true]
|
||||
(sci/binding [reflection-var false
|
||||
core/data-readers @core/data-readers]
|
||||
(let [{:keys [:version :shell-in :edn-in :shell-out :edn-out
|
||||
(let [{version-opt :version
|
||||
:keys [:shell-in :edn-in :shell-out :edn-out
|
||||
:help? :file :command-line-args
|
||||
:expressions :stream?
|
||||
:repl :socket-repl :nrepl
|
||||
:verbose? :classpath
|
||||
:main :uberscript :describe?] :as _opts}
|
||||
(parse-opts args)
|
||||
_ (when main (System/setProperty "babashka.main" main))
|
||||
_ (do ;; set properties
|
||||
(when main (System/setProperty "babashka.main" main))
|
||||
(System/setProperty "babashka.version" version))
|
||||
read-next (fn [*in*]
|
||||
(if (pipe-signal-received?)
|
||||
::EOF
|
||||
|
|
@ -532,7 +535,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
exit-code
|
||||
(or exit-code
|
||||
(second
|
||||
(cond version
|
||||
(cond version-opt
|
||||
[(print-version) 0]
|
||||
help?
|
||||
[(print-help) 0]
|
||||
|
|
|
|||
13
test-resources/babashka/version.clj
Normal file
13
test-resources/babashka/version.clj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(require '[clojure.string :as str])
|
||||
|
||||
(def babashka-version (System/getProperty "babashka.version"))
|
||||
;; e.g. 0.1.3-SNAPSHOT
|
||||
|
||||
(defn compare-version [v]
|
||||
(nat-int? (compare
|
||||
(mapv #(Integer. %)
|
||||
(take 3 (str/split babashka-version #"[\.\-]"))) v)))
|
||||
|
||||
(prn (compare-version [0 1 2])) ;; true
|
||||
(prn (compare-version [0 1 3])) ;; true
|
||||
(prn (compare-version [0 1 4])) ;; false
|
||||
|
|
@ -485,6 +485,10 @@
|
|||
(deftest data-diff-test
|
||||
(is (= [[nil 1] [nil 2] [1 nil 2]] (bb nil "(require '[clojure.data :as d]) (d/diff [1 1 2] [1 2 2])"))))
|
||||
|
||||
(deftest version-test
|
||||
(is (= "true\ntrue\nfalse\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "version.clj"))))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
Loading…
Reference in a new issue