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
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:with the following usage will yield an error:
The
add_mutually_exclusive_group()
function also accepts arequired
argument, to indicate that at least one of the mutually exclusive arguments is required:with the following usage will yield an error: