Skip to main content

dispatch

function

babashka.cli/dispatch

(dispatch [table args] [table args opts])
Subcommand dispatcher. Dispatches on longest matching command entry in `table` by matching subcommands to the `:cmds` vector and invoking the correspondig `:fn`. Table is in the form: ```clojure [{:cmds ["sub_1" .. "sub_n"] :fn f :args->opts [:lib]} ... {:cmds [] :fn f}] ``` When a match is found, `:fn` called with the return value of `parse-args` applied to `args` enhanced with: * `:dispatch` - the matching commands * `:args` - concatenation of unparsed commands and args * `:rest-cmds`: DEPRECATED, this will be removed in a future version Use an empty `:cmds` vector to always match or to provide global options. Provide an `:error-fn` to deal with non-matches. Each entry in the table may have additional `parse-args` options. For more information and examples, see [README.md](README.md#subcommands).

No examples yet. Be the first to add one!

Categories