-
Notifications
You must be signed in to change notification settings - Fork 362
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
[Bug] Parser assumes positional arguments which happen to match subcommand names are subcommands #23
Comments
Another workaround:
I see now the issue is in the |
I have submitted a naive PR to fix the issue, #24; however, a better fix may be possible. :) |
I'm thinking the correct behavior would be as follows:
Are there missing combinations? Is that the most logical behavior? |
Hmm, about half of those make no sense to me. :P
Am I misunderstanding? |
Ahh, I was associating demo with baz. I think that remains general (since a command and a subcommand are the same thing). So can you revaluate if those make sense with
? |
Ahh, OK, that makes much more sense now. So what you've described is roughly equivalent to:
|
I'm going to change that a bit, on an attempt to write it:
In this case, required positionals cannot fall through. Falling through positionals are dangerous, since there's no "name" associated with them. |
Fix #23: Respect fallthrough_ in _valid_subcommand
Does the code in the sub com branch do what you'd expect? I think I went with something more like what I described first. A little cleanup will be needed tomorrow. |
Yep, the subcom branch works for my use case. |
Polished and merged. Feel free to look at the added tests to verify that it does provide the expected behavior. |
Consider this demo program:
The app has two subcommands,
foo
andbar
, wherebar
takes a required positional argument namedbaz
. Suppose I want to runbar
withbaz
set to "qux":This works great! But suppose instead I want
baz
set to "foo":The parser has seen "foo" and given up parsing arguments for
bar
, but it instead context switched to thefoo
subcommand.There might be a use case for running multiple subcommands in the same invocation of the program, but the behavior we're seeing here is clearly incorrect, especially since there is no apparent way to fix it: adding
app.fallthrough(false)
and/orbar->fallthrough(false)
do not solve the issue.The only workaround I see so far is to convert
baz
to a named argument:This allows me to slip it by the parser correctly:
The text was updated successfully, but these errors were encountered: