Skip to content

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

@Sohalt

Description

@Sohalt

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").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions