From e1d52ef0e78f9b9fb8501b666dd6daa6eb7e607f Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 2 Jan 2024 17:09:11 +0100 Subject: [PATCH] dude --- src/babashka/cli.cljc | 12 ------------ test/babashka/cli_test.cljc | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/babashka/cli.cljc b/src/babashka/cli.cljc index bf16b9a..05a8806 100644 --- a/src/babashka/cli.cljc +++ b/src/babashka/cli.cljc @@ -625,18 +625,6 @@ {:error :input-exhausted :available-commands (keys (:cmd cmd-info))}))))))) -(comment - (dispatch [{:cmds ["foo"] :fn identity} - {:cmds [] :fn identity}] - []) - - (dispatch [{:cmds ["foo"] :fn identity}] ["foo"]) - (dispatch [{:cmds ["foo" "bar"] - :spec {:foo {:coerce :keyword}} - :fn identity}] ["foo" "bar" "--foo" "dude"]) - (dispatch [{:cmds ["foo" "bar" "baz"] :fn identity}] ["foo" "bar" "baz"]) - ) - (defn- dispatch-tree ([tree args] (dispatch-tree tree args nil)) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index f76dd61..2848d25 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -309,6 +309,18 @@ :spec {:foo {:coerce :keyword}} :fn identity}] ["foo" "bar" "--foo" "dude"]) +#_(comment + (dispatch [{:cmds ["foo"] :fn identity} + {:cmds [] :fn identity}] + []) + + (dispatch [{:cmds ["foo"] :fn identity}] ["foo"]) + (dispatch [{:cmds ["foo" "bar"] + :spec {:foo {:coerce :keyword}} + :fn identity}] ["foo" "bar" "--foo" "dude"]) + (dispatch [{:cmds ["foo" "bar" "baz"] :fn identity}] ["foo" "bar" "baz"]) + ) + (deftest dispatch-tree-test (d/deflet (def table [{:cmds ["foo" "bar"] @@ -328,19 +340,18 @@ (is (submap? {:dispatch ["foo" "bar" "baz"] , :opts {:baz true :quux :xyzzy}, :args nil} (cli/dispatch table ["foo" "bar" "--baz" "baz" "--quux" "xyzzy"])))) - #_#_(d/deflet - (def tree {:spec {:global {:coerce :boolean}} - "foo" {"bar" {:fn identity - "baz" {:fn identity}} - :spec {:bar {:coerce :keyword} - } - :fn identity}}) + (d/deflet + (def table [{:cmds [] :spec {:global {:coerce :boolean}}} + {:cmds ["foo"] :spec {:bar {:coerce :keyword}}} + {:cmds ["foo" "bar"] + :spec {:bar {:coerce :keyword}} + :fn identity}]) (is (submap? {:dispatch ["foo" "bar"] :opts {:bar :bar :global true} :args ["arg1"]} - (cli/dispatch-tree tree ["--global" "foo" "--bar" "bar" "bar" "arg1"])))) + (cli/dispatch table ["--global" "foo" "--bar" "bar" "bar" "arg1"])))) (testing "distinguish options at every level" (d/deflet