-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Subcommand precedence over arguments with SubcommandsNegateReqs #793
Comments
Thanks for the details! 😄 I'm a little confused on one point though, are you asking for when a subcommand conflicts with a required argument that the argument take precedence? Subcommands taking precedence also happens without requirements. println!("{:#?}", App::new("test")
.arg(Arg::with_name("arg1"))
.arg(Arg::with_name("arg2"))
.subcommand(SubCommand::with_name("sub"))
.get_matches()); Has the same issue as what's listed above. I'd be a little leary of having args take precdence though, as there's no way to "escape" a subcommand, but there is a way to "escape" an argument ( |
You are right,
This shouldn't be the default of course, but I think there is no other way¹ to implement my desired usage pattern:
I first noticed the problem when I wanted to send the (1) There actually is another way: You can "abuse" AllowExternalSubcommands, so the first argument becomes the "external subcommand" if it is no internal one. However, then you can't use any advanced functionality of |
Ah ok, I understand now! I do think this is doable, but I'm unsure of what to call this new setting. Bascially you want, "If an arg is used, forget about subcommands entirely." i.e. down't allow the Perhaps something like, |
Exactly! I think Edit: I think this new setting should only apply to positional arguments, so that something like |
Wow, thank you for the fast implementation, it works fine! Have you seen my edit about only applying this setting to positional arguments? I don't currently need it, but I think it could be useful in something like temporarily specifying a different config file or a flag like |
When using (at least) two positional arguments and a subcommand, the subcommand takes precedence when given as the second argument.
The goal is a cli of the following form, where the subcommand is only matched if it is the first argument. This makes it possible to e.g. use
sub
(orhelp
) as the value for the second argument.Example
test 1 sub
results in:while it would be much more useful (IMHO) if it resulted in:
Additionally, when the
suggestions
feature is enabled, any prefix or extended version ofsub
with at least length 2 triggers a "Did you mean 'sub'?" help screen. Withoutsuggestions
, only exact matches cause the described problem.A workaround is to use
test -- 1 sub
ortest 1 -- sub
, which results in the second output.Changing the meaning of
SubcommandsNegateReqs
is of course not backwards compatible, but a new setting that prefers arguments over subcommands could be introduced.The text was updated successfully, but these errors were encountered: