diff --git a/CHANGELOG.md b/CHANGELOG.md index 08c941b1..e7bae1cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ A preview of the next release can be installed from - Add `java.util.ScheduledFuture` - Support `Runnable` to be used without import - Allow `catch` to be used as var name +- [#1646](https://github.com/babashka/babashka/issues/1646): command-line-args are dropped when file exists with same name ## 1.3.186 (2023-11-02) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 3d1aee96..99aa73f6 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -741,11 +741,10 @@ Use bb run --help to show this help output. (if-not opt opts-map ;; FILE > TASK > SUBCOMMAND (cond - (.isFile (io/file opt)) - (if (or (:file opts-map) (:jar opts-map)) - opts-map ; we've already parsed the file opt - (parse-file-opt options opts-map)) - + (and (not (or (:file opts-map) + (:jar opts-map))) + (.isFile (io/file opt))) + (parse-file-opt options opts-map) (contains? tasks opt) (assoc opts-map :run opt @@ -1181,7 +1180,6 @@ Use bb run --help to show this help output. edn)] (vreset! common/bb-edn edn))) opts (parse-opts args opts) - ;; _ (.println System/err (str bb-edn)) min-bb-version (:min-bb-version bb-edn)] (System/setProperty "java.class.path" "") (when min-bb-version diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 1d80f4b6..c223225e 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -69,7 +69,9 @@ (testing "file opts parsing does not mess with :command-line-args" (is (= {:prn true, :expressions ["(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"]} + (main/parse-opts ["README.md"] {:file "foo"}))))) (deftest version-test (is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))