You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use"cli"actorMainnewcreate(env: Env) =>
let spec = trymake_spec()? elsereturnendlet cmd =
matchCommandParser(spec).parse(env.args, env.vars)
| let c: Command => c
elsereturnend
env.out.print("Value of arg: " + cmd.option("arg").string())
funmake_spec(): CommandSpec? =>
let root = CommandSpec.parent("cmd", "My cmd",
[ OptionSpec.string("arg", "an arg"where default' = "foo") ])?
let sub = CommandSpec.leaf("sub", "My subcmd")?
root.add_command(sub)?
root.add_help()?
root
When running this, as ./cmd sub, Value of arg: is printed to the command line. I believe the problem is in command_parser.pony on line 101, where parsing a parent command recurses into parsing a sub-command and then returns. Filling in of default options would occur later, on line 147, but we never get that far.
Two possibilities which spring to mind are
when adding a spec to a parent, add a back-reference in the child so that when options() is called, it returns non-duplicated parent options
don't return from parsing a sub command, but keep track of the fact we've already parsed one sub-command
both suggestions raise questions around duplicated options between the parent and child, and how they should work.
As a motivating example, my use case is to have a config file for my command line utility which should apply to all sub-commands, but defaults to a sensible value if the user doesn't specify one.
Also, when debugging this issue, I found it would have been useful to know if an option was set, rather than having just a default fake option returned. There's a couple of places this could be done, but I think the easiest is to have an is_set or something similar on the Command class.
The text was updated successfully, but these errors were encountered:
Consider the following setup,
When running this, as
./cmd sub
,Value of arg:
is printed to the command line. I believe the problem is incommand_parser.pony
on line 101, where parsing a parent command recurses into parsing a sub-command and then returns. Filling in of default options would occur later, on line 147, but we never get that far.Two possibilities which spring to mind are
options()
is called, it returns non-duplicated parent optionsboth suggestions raise questions around duplicated options between the parent and child, and how they should work.
As a motivating example, my use case is to have a config file for my command line utility which should apply to all sub-commands, but defaults to a sensible value if the user doesn't specify one.
Also, when debugging this issue, I found it would have been useful to know if an option was set, rather than having just a default fake option returned. There's a couple of places this could be done, but I think the easiest is to have an
is_set
or something similar on theCommand
class.The text was updated successfully, but these errors were encountered: