-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
flag value misparsed as subcommand #1777
Comments
Interesting. I can confirm this with kubectl (which uses cobra). In the example below, I try to run a pod in a namespace called "run", using the Fails:
This works:
|
Another thing that is weird about this: If you have multiple sub commands, the problem only occurs when the flag value matches the particular sub command you are running. So for example, kubectl has a
But if I use
|
I think I see what's causing this and it shouldn't be too complicated to fix. I will take a look at it and submit a PR with a fix. |
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
|
still broken |
When the command searches args to find the arg matching a particular subcommand name, it needs to ignore flag values, as it is possible that the value for a flag might match the name of the sub command. This change improves argsMinusFirstX() to ignore flag values when it searches for the X to exclude from the result. Fixes spf13/cobra#1777 Merge spf13/cobra#1781
it looks like the parser is having trouble with space delimited persistent flags, where a sub command aligns with the value of the first of many flags:
for
./app -z one -o one two
: https://go.dev/play/p/cKaEuTEhWAZwanted:
got:
note: this does not trigger for the following cases
The text was updated successfully, but these errors were encountered: