Skip to content
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

Add functions required_unless_eq_any and required_unless_eq_all for Arg and ArgGroup #4682

Open
2 tasks done
rob-p opened this issue Jan 28, 2023 · 1 comment
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

Comments

@rob-p
Copy link

rob-p commented Jan 28, 2023

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 with required_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 (and ArgGroup, I believe?) like required_ifs and required_if_eq_any and, I propose the addition of methods:

  • required_unless_eq_any and
  • required_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.

@rob-p rob-p added the C-enhancement Category: Raise on the bar on expectations label Jan 28, 2023
@epage
Copy link
Member

epage commented Feb 23, 2023

Sorry for the slow response!

Another route for this is to extend ArgPredicate.

A challenge we have is there is an arbitrary set of functionality people ask of clap while we are working on shrinking clap (#2037, #1365) and we have been exploring other ways of handling this in #3476. This makes me hesitant every time there is a new request for an additional variant of existing functionality.

@epage epage added S-waiting-on-decision Status: Waiting on a go/no-go before implementing A-validators Area: ArgMatches validation logi labels Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants