Skip to content

Commit 187dd20

Browse files
committed
TCLI-107 handle edge case with subcommands
Signed-off-by: Sean Corfield <sean@corfield.org>
1 parent 99afa1e commit 187dd20

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/clojure/clojure/tools/cli.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@
637637
:strict strict
638638
:subcommand subcommand)]
639639
{:options opts
640-
:arguments (into rest-args implicit-args)
640+
:arguments (into implicit-args rest-args)
641641
:summary ((or summary-fn summarize) specs)
642642
:errors (when (seq errors) errors)}))
643643

src/test/clojure/clojure/tools/cli_test.cljc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,22 @@
470470
(is (= (:errors (parse-opts ["-a" "-b"]
471471
[["-b" "--beta"]]
472472
:subcommand :implicit))
473+
nil))
474+
(is (= (:arguments (parse-opts ["-a" "foo" "-b"]
475+
[["-b" "--beta"]]
476+
:subcommand :explicit))
477+
["foo" "-b"]))
478+
(is (= (:errors (parse-opts ["-a" "foo" "-b"]
479+
[["-b" "--beta"]]
480+
:subcommand :explicit))
481+
["Unknown option: \"-a\""]))
482+
(is (= (:arguments (parse-opts ["-a" "foo" "-b"]
483+
[["-b" "--beta"]]
484+
:subcommand :implicit))
485+
["-a" "foo" "-b"]))
486+
(is (= (:errors (parse-opts ["-a" "foo" "-b"]
487+
[["-b" "--beta"]]
488+
:subcommand :implicit))
473489
nil)))
474490
(testing "does not merge over default values when :no-defaults is true"
475491
(let [option-specs [["-p" "--port PORT" :default 80]

0 commit comments

Comments
 (0)