-
-
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
Question/Feature request: Any way to do required_ifs "flags exists". #1126
Comments
I'm not opposed to adding something like that, however I'll explain why it doesn't exist (yet). When dealing with flags and requirements, since they are a simple on/off switch, if you know From a UX standpoint, the user isn't supplying any additional information by being forced to pass The only time requiring an additional flag is a good idea is when the task is destructive (like deleting, etc.) and the user needs to confirm that they're sure they know what they're doing (by including the flag) such as However, in these circumstances it's far better to have a custom error message telling the user what is about to happen and why the extra flag is required. A generic clap error of, "-C is required but wasn't used" could actually be harmful here, since the user will almost always just blindly copy the |
Closing for now to get 3.x out the door. We can re-address after release if needed. |
I'm leaving it closed for the time being |
Is there any way to do "required if other options present"? For example |
Interesting. We support "present" for defaults but not requires or required. #3008 has the potential for making our required, requires, defaults, etc more general. |
Clap version: 2.29.0
I'll start with the problem I am trying to solve:
I have the flags -A, -B, -C, which are all optional by themselves. However, if both -A, and -B are used, -C must also be used. (-C takes some values that -A and -B need)
Clap has
required_unless_all(name)
, but doesn't have the opposite of that e.g.required_if_all(name)
?I know clap has
required_ifs()
, but that compares the input from an argument with a value, but the value doesn't matter in this case, only that the flags are present or not.Having
requires()
on -A and -B also won't work in this case, as only having one of them will make -C required.requires_all()
does the opposite of what I want, requiring both -A and -B to be used -C can be usedNone of the above is unexpected, (the documentation is really good at explaining each option 👍 ), but there doesn't seem to be a
required_if_all([names])
. Any ideas?The text was updated successfully, but these errors were encountered: