Add functions required_unless_eq_any
and required_unless_eq_all
for Arg
and ArgGroup
#4682
Open
2 tasks done
Labels
A-validators
Area: ArgMatches validation logi
C-enhancement
Category: Raise on the bar on expectations
S-waiting-on-decision
Status: Waiting on a go/no-go before implementing
Please complete the following tasks
Clap Version
4.1.4
Describe your use case
I would like to define an argument or argument group that is required unless some other argument takes on a specific value.
This would be very useful in my use case (a tool processing single-cell gene expression data), because in some situations, when a particular common protocol is used and passed as the value to some argument (in this case called
--geometry
), the values of several other arguments can be inferred and should no longer be required. However, if the--geometry
is not one of these common values, then the other arguments should be required.If the
--geometry
argument only took on a small number of possible values, then something like this might be possible withrequired_if
, by listing all of the other values for which the argument should still be required. However, in my use case, the potential values to--geometry
are potentially unbounded since the user can provide custom values that are later parsed and interpreted by the program. Thus, I need a way to specify a list of specific values for which other arguments should not be required.Describe the solution you'd like
Just as there are now methods on
Arg
(andArgGroup
, I believe?) likerequired_ifs
andrequired_if_eq_any
and, I propose the addition of methods:required_unless_eq_any
andrequired_unless_eq_all
These do pretty much what it says on the label. The first says an argument or argument group is required unless any of the listed conditions are satisfied (i.e. some other argument has a particular value), and the second says an argument or argument group is required unless all of the listed conditions are satisfied.
Given the existence of the other functions that are already present for related functionality, these seem a natural addition.
Alternatives, if applicable
No response
Additional Context
I brought up a discussion about this here, but I am pretty sure that no way currently exists to accomplish this without the functionality requested above.
The text was updated successfully, but these errors were encountered: