-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
required_unless produces error on a flag #533
Comments
The thought process behind that is somewhat opinionated...and being that Currently flags can't be required because they're simply boolean values. If one should be required, then I would have thought the developer should "imply" it's use (perhaps with a note in the usage stating that it's implied in certain cases). IMO if flag The case against my thinking would be forcing the user to type I'm curious to know what others thoughts on the matter are? If the above reasoning is correct, and there is a case where |
I completely agree with the rationale for not allowing Here's my use case: I have a command similar to I'd be happy with another way of doing this, such as a |
Ah, ok I understand, thanks! I think what I'll try to do is add a method |
…f the args Unlike the previous ArgGroups, which made all args in the group mutually exclusive, one can now use `ArgGroup::multiple(true)` which states, "At least one of the args must be used, and using more than one is also OK." Closes #533
This is implemented with #535 |
@kbknapp Thanks for the fast fix! I'll test this today, including what the error message looks like for not providing one of the arguments. Any plans for a clap release incorporating this? (I can pull clap from git for testing, but it'd be nice to have a released version on crates.io.) |
@kbknapp Just tested this; works perfectly. Thanks! |
@joshtriplett Once #376 #536 are merged I'll post the new version to crates.io. If #376 takes too much time I may just bump and publish prior. So in the next day or so I should have the new version out on crates.io |
As the clap documentation notes, you can't make a flag required. However, it should be possible to mark a flag as
.required_unless
another flag or argument. Doing so currently produces a runtime panic.You can work around this with another argument by marking the argument as
.required_unless
the flag instead. However, given two flags you can't.(Alternatively, if this would make the require requirements more difficult to express, the documentation could instead explicitly note this case and point to another way to say "one or more of these are required".)
The text was updated successfully, but these errors were encountered: