diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e2efe08..5c7878d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 +## 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) - Add `clojure.reflect/reflect` diff --git a/src/babashka/main.clj b/src/babashka/main.clj index d7b8052c..b4f48ddb 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -746,8 +746,7 @@ Use bb run --help to show this help output. (and (not (or (:file opts-map) (:jar opts-map))) (.isFile (io/file opt))) - (let [[args opts] (parse-file-opt options opts-map)] - (assoc opts :command-line-args args)) + (parse-file-opt options opts-map) (contains? tasks opt) (assoc opts-map :run opt @@ -1147,7 +1146,6 @@ Use bb run --help to show this help output. (list* "--jar" bin-jar "--" args) args) [args opts] (parse-global-opts args) - ;; TODO: drop jar file from opts [args {:keys [jar file config merge-deps debug] :as opts}] (if-not (or (:file opts) (:jar opts)) diff --git a/test-resources/script_with_overlapping_opts.clj b/test-resources/script_with_overlapping_opts.clj index 796f8250..5b71e3dc 100644 --- a/test-resources/script_with_overlapping_opts.clj +++ b/test-resources/script_with_overlapping_opts.clj @@ -1 +1 @@ -(prn (first *command-line-args*)) +(prn *command-line-args*) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 96852475..424c17b7 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -388,7 +388,7 @@ even more stuff here\" (try (spit "uberjar" "#!/usr/bin/env bb\n(+ 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")))))) (deftest min-bb-version-test diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 4e892fc4..3ee6ab1b 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -73,7 +73,8 @@ (main/parse-opts ["-e" "(prn :foo)"] opts))))) (is (= {:file "foo", :command-line-args ["README.md"]} (main/parse-opts ["README.md"] {:file "foo"}))) - (prn (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"))) + (is (= ["version"] (bb nil (fs/file "test-resources" "script_with_overlapping_opts.clj") "version"))))) (deftest version-test (is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))