-
Notifications
You must be signed in to change notification settings - Fork 347
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
Return an error if the same flag is provided twice with different values #72
Comments
I feel like that is a custom flag type. I don't know of any unix command that complains when the same flag is given twice. All of them I know of either use both values or the last value, depending on the type of flag... |
Now that pflag supports StringArray and friends I'm now using those in rclone so this issue is less important for me personally now. However duplicated flags especially with arguments, when the parser can't cope with them, should make an error. Just because getopt(3) is lazy doesn't mean we have to be! |
I think we should apply this as default for all non-sliced types. PTAL #151. I introduced a new method |
here's an example (not a core unix command, but it's on most systems these days)
|
We allow a container to be connected to several cni networks but only if they are listed comma sperated. This is not intuitive for users especially since the flag parsing allows multiple string flags but only would take the last value. see: spf13/pflag#72 Also get rid of the extra parsing logic for pods. The invalid options are already handled by `pkg/specgen`. A test is added to prevent a future regression. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
I upvote this feature request. Here's my use case: depending on the context of a sub-command, some flags might have different meaning. The other use case is that the users might copy/paste or reuse commands from history and modify some of the arguments. It might happen that the command looks like I'm happy to help designing this feature and working on PRs. Line 481 in d5e0c06
|
In rclone/rclone#506 a user is rightly complaining about the fact that two
--exclude
flags don't work in rclone and it didn't warn him.Could pflag return an error if you provide the same flag twice with different values?
Thanks
Nick
The text was updated successfully, but these errors were encountered: