-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Dispatch tree #75
Dispatch tree #75
Conversation
|
Comparison on string fails on Windows due to newlines being different on Windows |
Note: it seems that all options are gathered in one bag:
Are there situations where one might want to see where options came from? Like |
TODO for @borkdude : check how argparse works in Python regarding this |
Yep, noticed that. I'm not entirely sure dispatch should print an error at all. I think it's generally bad behavior for libraries to print something. That's why I added the Maybe dispatch-tree could call |
Also with (def table [{:cmds ["foo"] :fn (fn [_] (print "foo")} {:cmds ["foo" "bar"} :fn (fn [_] (print "bar")]) old behavior: (dispatch table ["foo" "bar"])
"foo" new behavior (dispatch table ["foo" "bar"])
"bar" |
yes. I could do something like: (cli/dispatch-tree' tree ["foo" "--foo" "dude" "bar" "baz" "--quux" "xyzzy" "dude"] nil)
{:opts {["foo"] {:foo "dude} ["foo" "bar" "baz"] {:quux "xyzzy"}}} Though it feels a bit heavy |
Did some research with @lispyclouds to how argparse (Python) does stuff:
This returns:
Since python dicts are ordered (by insertion), you can retrieve back the information which subcommand got which options. |
Superseded |
Expand
dispatch
to also work on a tree instead of a table.The tree consists of nested maps with string keys for command parts and keyword keys for opts to be passed to
parse-args
.e.g.
encodes a command
foo bar baz
that invokesidentity
:There can be options for
parse-args
, such as:spec
s at every level, e.g.If there is no
:fn
key at the node that's reached by parsing the args, the dispatch will return an error:There's a
table->tree
function to convert tables to trees.