Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose prefix in dispatch error no-match and input-exhausted cases #92

Closed
Sohalt opened this issue Mar 13, 2024 · 6 comments · Fixed by #93
Closed

expose prefix in dispatch error no-match and input-exhausted cases #92

Sohalt opened this issue Mar 13, 2024 · 6 comments · Fixed by #93

Comments

@Sohalt
Copy link
Contributor

Sohalt commented Mar 13, 2024

It would be helpful to have the cmds

:dispatch cmds
also exposed in the error data for the :no-match and :input-exhausted cases, because it's helpful to know how far dispatch traversed the command tree until it encountered the error to give better error messages.

Specifically, if I have

(def cmd-table
  [{:cmds ["foo" "bar"] :fn identity}
   {:cmds ["foo" "baz"] :fn identity}])
(dispatch cmd-table ["foo" "quux"] {:error-fn identity})
;; => {:type :org.babashka/cli, :wrong-input "quux", :all-commands ("bar" "baz"), :cause :no-match, :opts {}}

if I had the prefix "foo", I could genenrate an error message that lists all valid commands with prefix "foo" (i.e. "foo bar" "foo baz").

@borkdude
Copy link
Contributor

Feel free to submit a PR, I prefer this to be called :cmds since that's what it's also called in the dispatch table?

@Sohalt
Copy link
Contributor Author

Sohalt commented Mar 13, 2024

It's called :cmds in the dispatch table, but is (and was) called :dispatch in the args to the fn called by dispatch. I don't have strong opinions though.

@borkdude
Copy link
Contributor

Nowhere in a public API is the name :dispatch exposed right? (I mean on master, not in a previous WIP PR)

@Sohalt
Copy link
Contributor Author

Sohalt commented Mar 13, 2024

It is (and was) exposed on master as part of the dispatch fn, first introduced here 72edb28#diff-17c5192974650f8980e4dbdaa029b04d0ee52e3f3d77afc46a1944d79448aa0bR214

@Sohalt
Copy link
Contributor Author

Sohalt commented Mar 13, 2024

Wait, looks c870e24 removed it again.
But 712fee8#diff-17c5192974650f8980e4dbdaa029b04d0ee52e3f3d77afc46a1944d79448aa0bR634 reintroduced it.
The docs listed it the entire time

cli/API.md

Line 77 in 05868bf

* `:dispatch` - the matching commands
, which is what I was looking at when implementing the dispatch-tree changes.

@borkdude
Copy link
Contributor

ok, let's keep dispatch then, didn't realize we already exposed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants