Skip to content
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

Open
swills opened this issue Dec 24, 2023 · 4 comments
Open

non-boolean flags found on sub commands regardless of order #2092

swills opened this issue Dec 24, 2023 · 4 comments

Comments

@swills
Copy link

swills commented Dec 24, 2023

It seems like flags shouldn't be found for sub-commands but sometimes they are:

$ helm --starter .
Error: unknown flag: --starter
$ helm --starter . create a
Creating a

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.

@marckhouzam
Copy link
Collaborator

marckhouzam commented Dec 25, 2023

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?

@swills
Copy link
Author

swills commented Dec 25, 2023

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 EnableCommandSorting.

@Luap99
Copy link
Contributor

Luap99 commented Dec 28, 2023

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

@swills
Copy link
Author

swills commented Dec 28, 2023

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:

cirrinactl --name builder0 vm get
cirrinactl vm --name builder0 get
cirrinactl vm get --name builder0

Please let me know if I'm doing something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants