parent
ecbbd7ab84
commit
6dc3110b3c
5 changed files with 16 additions and 8 deletions
|
|
@ -7,6 +7,10 @@ A preview of the next release can be installed from
|
||||||
|
|
||||||
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
|
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
- [#1658](https://github.com/babashka/babashka/issues/1658): fix command line parsing for scripts that parse `--version` or `version` etc
|
||||||
|
|
||||||
## 1.3.187 (2023-01-09)
|
## 1.3.187 (2023-01-09)
|
||||||
|
|
||||||
- Add `clojure.reflect/reflect`
|
- Add `clojure.reflect/reflect`
|
||||||
|
|
|
||||||
|
|
@ -722,9 +722,10 @@ Use bb run --help to show this help output.
|
||||||
(let [opt (first options)]
|
(let [opt (first options)]
|
||||||
(if (and opt (and (fs/exists? opt)
|
(if (and opt (and (fs/exists? opt)
|
||||||
(not (fs/directory? opt))))
|
(not (fs/directory? opt))))
|
||||||
[(next options) (assoc opts-map
|
[nil (assoc opts-map
|
||||||
(if (str/ends-with? opt ".jar")
|
(if (str/ends-with? opt ".jar")
|
||||||
:jar :file) opt)]
|
:jar :file) opt
|
||||||
|
:command-line-args (next options))]
|
||||||
[options opts-map])))
|
[options opts-map])))
|
||||||
|
|
||||||
(defn parse-opts
|
(defn parse-opts
|
||||||
|
|
@ -745,8 +746,7 @@ Use bb run --help to show this help output.
|
||||||
(and (not (or (:file opts-map)
|
(and (not (or (:file opts-map)
|
||||||
(:jar opts-map)))
|
(:jar opts-map)))
|
||||||
(.isFile (io/file opt)))
|
(.isFile (io/file opt)))
|
||||||
(let [[args opts] (parse-file-opt options opts-map)]
|
(parse-file-opt options opts-map)
|
||||||
(assoc opts :command-line-args args))
|
|
||||||
(contains? tasks opt)
|
(contains? tasks opt)
|
||||||
(assoc opts-map
|
(assoc opts-map
|
||||||
:run opt
|
:run opt
|
||||||
|
|
@ -1146,12 +1146,12 @@ Use bb run --help to show this help output.
|
||||||
(list* "--jar" bin-jar "--" args)
|
(list* "--jar" bin-jar "--" args)
|
||||||
args)
|
args)
|
||||||
[args opts] (parse-global-opts args)
|
[args opts] (parse-global-opts args)
|
||||||
;; TODO: drop jar file from opts
|
|
||||||
[args {:keys [jar file config merge-deps debug] :as opts}]
|
[args {:keys [jar file config merge-deps debug] :as opts}]
|
||||||
(if-not (or (:file opts)
|
(if-not (or (:file opts)
|
||||||
(:jar opts))
|
(:jar opts))
|
||||||
(parse-file-opt args opts)
|
(parse-file-opt args opts)
|
||||||
[args opts])
|
[args opts])
|
||||||
|
;; _ (prn :args args :opts opts)
|
||||||
abs-path #(-> % io/file .getAbsolutePath)
|
abs-path #(-> % io/file .getAbsolutePath)
|
||||||
config (cond
|
config (cond
|
||||||
config (if (fs/exists? config) (abs-path config)
|
config (if (fs/exists? config) (abs-path config)
|
||||||
|
|
|
||||||
1
test-resources/script_with_overlapping_opts.clj
Normal file
1
test-resources/script_with_overlapping_opts.clj
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
(prn *command-line-args*)
|
||||||
|
|
@ -388,7 +388,7 @@ even more stuff here\"
|
||||||
(try
|
(try
|
||||||
(spit "uberjar" "#!/usr/bin/env bb\n(+ 1 2 3)")
|
(spit "uberjar" "#!/usr/bin/env bb\n(+ 1 2 3)")
|
||||||
(vreset! common/bb-edn '{:tasks {uberjar (+ 1 2 3)}})
|
(vreset! common/bb-edn '{:tasks {uberjar (+ 1 2 3)}})
|
||||||
(is (= "uberjar" (:file (main/parse-opts ["uberjar"]))))
|
(is (= {:file "uberjar", :command-line-args '("--version")} (second (main/parse-opts ["uberjar" "--version"]))))
|
||||||
(finally (fs/delete "uberjar"))))))
|
(finally (fs/delete "uberjar"))))))
|
||||||
|
|
||||||
(deftest min-bb-version-test
|
(deftest min-bb-version-test
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns babashka.main-test
|
(ns babashka.main-test
|
||||||
{:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [working?]}}}}
|
{:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [working?]}}}}
|
||||||
(:require
|
(:require
|
||||||
|
[babashka.fs :as fs]
|
||||||
[babashka.main :as main]
|
[babashka.main :as main]
|
||||||
[babashka.test-utils :as test-utils]
|
[babashka.test-utils :as test-utils]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
|
|
@ -71,7 +72,9 @@
|
||||||
(-> (let [[_ opts] (main/parse-file-opt ["-e" "(prn :foo)"] {})]
|
(-> (let [[_ opts] (main/parse-file-opt ["-e" "(prn :foo)"] {})]
|
||||||
(main/parse-opts ["-e" "(prn :foo)"] opts)))))
|
(main/parse-opts ["-e" "(prn :foo)"] opts)))))
|
||||||
(is (= {:file "foo", :command-line-args ["README.md"]}
|
(is (= {:file "foo", :command-line-args ["README.md"]}
|
||||||
(main/parse-opts ["README.md"] {:file "foo"})))))
|
(main/parse-opts ["README.md"] {:file "foo"})))
|
||||||
|
(is (= ["--version"] (bb nil (fs/file "test-resources" "script_with_overlapping_opts.clj") "--version")))
|
||||||
|
(is (= ["version"] (bb nil (fs/file "test-resources" "script_with_overlapping_opts.clj") "version")))))
|
||||||
|
|
||||||
(deftest version-test
|
(deftest version-test
|
||||||
(is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))
|
(is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue