-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
non-boolean flags found on sub commands regardless of order #2092
Comments
Interesting. I wonder how we should interpret this. Should cobra accept flags in any order, or should it require them to follow the command they apply to? Or said another way is the non-boolean flag the bug or is the bug that boolean flags are not accepted like this? |
Personally, my expectation based on the majority of software I've used is that the flag has to follow the command it belongs to. (I guess it's a nice convenience in some situations that it can be sort of "out of order" but I can see that being confusing in certain situations too.) So, IMHO, cobra should behave like I expect and require the flag to follow the command. But if there are disagreements or uncertainty, perhaps this could be configurable, similar to |
Can you provide an example code to reproduce? I am not aware of cobra doing this, this looks like helm is ignoring the errors: https://github.com/helm/helm/blob/main/cmd/helm/root.go#L148-L153 |
I see the same thing happening in my code here: https://gitlab.com/swills/cirrina/-/tree/main/cirrinactl These three all produce the same results:
Please let me know if I'm doing something wrong. |
It seems like flags shouldn't be found for sub-commands but sometimes they are:
The --starter flag is for the create sub-command only and so as far as I understand it should have to be after the "create". And yet, it works fine here. I've seen it with other projects and code using cobra too, helm is just a prominent example. I can provide more detailed test code if needed.
The text was updated successfully, but these errors were encountered: