p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.67k stars 244 forks source link

Closes #221 #301

Closed p-ranav closed 12 months ago

p-ranav commented 12 months ago

Create a mutually exclusive group using program.add_mutually_exclusive_group(required = false). `argparse`` will make sure that only one of the arguments in the mutually exclusive group was present on the command line:

auto &group = program.add_mutually_exclusive_group();
group.add_argument("--first");
group.add_argument("--second");

with the following usage will yield an error:

foo@bar:/home/dev/$ ./main --first 1 --second 2
Argument '--second VAR' not allowed with '--first VAR'

The add_mutually_exclusive_group() function also accepts a required argument, to indicate that at least one of the mutually exclusive arguments is required:

auto &group = program.add_mutually_exclusive_group(true);
group.add_argument("--first");
group.add_argument("--second");

with the following usage will yield an error:

foo@bar:/home/dev/$ ./main
One of the arguments '--first VAR' or '--second VAR' is required