You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
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 used
None 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:
Comment by kbknapp Tuesday Jan 09, 2018 at 16:51 GMT
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 -A and -B requires -C (as the programmer), you could just act as if-C was used. I'd recommend telling the user via a help message or something, ("using -A and -B together implies-C", etc.).
From a UX standpoint, the user isn't supplying any additional information by being forced to pass -C since it's a flag. The only thing they're saying is essentially, "I know the -C switch is required."
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 --force usually, or -D in git branch.
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 -C argument and not know why.
Tuesday Dec 12, 2017 at 04:54 GMT
Originally opened as clap-rs/clap#1126
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: