Skip to content

Commit

Permalink
dude
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jan 2, 2024
1 parent e766870 commit e1d52ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
12 changes: 0 additions & 12 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 19 additions & 8 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand Down

0 comments on commit e1d52ef

Please sign in to comment.