From a28ac4226a5b68b21d0227e592c39a91d131e09d Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 21 Nov 2025 17:02:21 +0100 Subject: [PATCH 1/2] Fix #126: wonky behavior with - value --- CHANGELOG.md | 4 ++++ src/babashka/cli.cljc | 3 ++- test/babashka/cli_test.cljc | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 211a3d9..7653110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ For breaking changes, check [here](#breaking-changes). [Babashka CLI](https://github.com/babashka/cli): turn Clojure functions into CLIs! +## Unreleased + +- [#126](https://github.com/babashka/cli/issues/126): `-` value accidentally parsed as option, e.g. `--file -` + ## v0.8.66 (2025-07-12) - [#122](https://github.com/babashka/cli/issues/122): introduce new diff --git a/src/babashka/cli.cljc b/src/babashka/cli.cljc index 04288f0..e36af4f 100644 --- a/src/babashka/cli.cljc +++ b/src/babashka/cli.cljc @@ -85,7 +85,7 @@ (try (let [s ^String s fst-char (first-char s) - #?@(:clj [leading-num-char (if (= fst-char \-) + #?@(:clj [leading-num-char (if (= \- fst-char) (second-char s) fst-char)])] (cond (or (= "true" s) @@ -239,6 +239,7 @@ snd-char (second-char arg) hyphen-opt? (and (not= :keywords mode) (= \- fst-char) + (> (count arg) 1) (let [k (keyword (subs arg 1))] (or (contains? known-keys k) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index e8932d2..6c303e2 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -654,3 +654,6 @@ (cli/parse-args ["--foo" "1" "--foo" "2"] {:repeated-opts true :spec {:foo {:coerce []}}}))) (is (= {:args ["2"], :opts {:foo [1]}} (cli/parse-args ["--foo" "1" "2"] {:repeated-opts true :spec {:foo {:coerce []}}})))) + +(deftest issue-126-test + (is (= {:file "-"} (cli/parse-opts ["--file" "-"])))) From 03cb12c348929936775648336bd4a136f775fa57 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 21 Nov 2025 20:02:58 +0100 Subject: [PATCH 2/2] wip --- test/babashka/cli_test.cljc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index 6c303e2..b3dd800 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -656,4 +656,5 @@ (cli/parse-args ["--foo" "1" "2"] {:repeated-opts true :spec {:foo {:coerce []}}})))) (deftest issue-126-test - (is (= {:file "-"} (cli/parse-opts ["--file" "-"])))) + (is (= {:file "-"} (cli/parse-opts ["--file" "-"]))) + (is (= {:file "-"} (cli/parse-opts ["-"] {:args->opts [:file]}))))