From 4c76124798ae534d534d712fb83a18298a606427 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 8 May 2024 12:55:26 +0200 Subject: [PATCH] Fix #98: internal options should not interfere with :restrict (#99) --- CHANGELOG.md | 4 ++++ src/babashka/cli.cljc | 3 ++- test/babashka/cli_test.cljc | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2350ba3..89b83db 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 + +- Fix [#98](https://github.com/babashka/cli/issues/98): internal options should not interfere with :restrict + ## v0.8.59 (2024-04-30) - Fix [#96](https://github.com/babashka/cli/issues/96): prevent false defaults from being removed/ignored diff --git a/src/babashka/cli.cljc b/src/babashka/cli.cljc index c510553..1b7f1a0 100644 --- a/src/babashka/cli.cljc +++ b/src/babashka/cli.cljc @@ -463,7 +463,8 @@ opts)] (when restrict (doseq [k (keys opts)] - (when-not (contains? restrict k) + (when (and (not (contains? restrict k)) + (not= (namespace k) "babashka.cli")) (error-fn {:cause :restrict :msg (str "Unknown option: " k) :restrict restrict diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index fe2fa1a..3c01a56 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -558,3 +558,17 @@ (deftest issue-91-keyword-mode-overrides-hypens-mode (is (= {:args ["--baz"], :opts {:foo 1}} (cli/parse-args [":foo" 1 "--baz"] {})))) + +(deftest issue-98-dispatch+restrict-test + (is (thrown? Exception + (cli/dispatch [{:cmds ["foo"] + :fn identity + :spec {:x {:coerce :boolean}}}] + ["foo" "--y"] + {:restrict true}))) + (is (= {:dispatch ["foo"], :opts {}, :args nil} + (cli/dispatch [{:cmds ["foo"] + :fn identity + :spec {:x {:coerce :boolean}}}] + ["foo"] + {:restrict true}))))