spf13/cobra

non-boolean flags found on sub commands regardless of order

swills opened this issue · 4 comments

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.

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