TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.7k stars 149 forks source link

Feature Request: All-or-none structs #535

Open formlogic-robert opened 8 months ago

formlogic-robert commented 8 months ago

This is a small idea as it relates to the use of structopt in production environments.

It would be useful if a struct, in a multi-nested struct configuration, could be flagged to require all of its options to be provided whenever at least one of them is, or none at all. The usefulness of this is to prevent partial configurations in production environments which can lead to difficult-to-debug issues.

The feature would be used by specifying all_or_none in the struct trait's parameters:

#[derive(StructOpt)]
#[StructOpt(all_or_none)]

This saves having to write many required_if statements for all permutations of default parameters. If you specified a single parameter, but not other required parameters, regardless of whether they have defaults, the argument parsing would fail.

epage commented 8 months ago

Note that structopt has been pulled into clap as of v3 and all future development is happening within clap. See #525

Something like this might be able to be done with ArgGroups in clap.