[#479] Add babashka.version system property

This commit is contained in:
Michiel Borkent 2020-06-26 10:38:58 +02:00 committed by GitHub
parent 475622f7f4
commit e095e1485a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -444,14 +444,17 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
(binding [*unrestricted* true] (binding [*unrestricted* true]
(sci/binding [reflection-var false (sci/binding [reflection-var false
core/data-readers @core/data-readers] 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 :help? :file :command-line-args
:expressions :stream? :expressions :stream?
:repl :socket-repl :nrepl :repl :socket-repl :nrepl
:verbose? :classpath :verbose? :classpath
:main :uberscript :describe?] :as _opts} :main :uberscript :describe?] :as _opts}
(parse-opts args) (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*] read-next (fn [*in*]
(if (pipe-signal-received?) (if (pipe-signal-received?)
::EOF ::EOF
@ -532,7 +535,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
exit-code exit-code
(or exit-code (or exit-code
(second (second
(cond version (cond version-opt
[(print-version) 0] [(print-version) 0]
help? help?
[(print-help) 0] [(print-help) 0]

View 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

View file

@ -485,6 +485,10 @@
(deftest data-diff-test (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])")))) (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 ;;;; Scratch
(comment (comment