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

Closes #221 #301

Merged
merged 9 commits into from
Nov 4, 2023
Merged

Closes #221 #301

merged 9 commits into from
Nov 4, 2023

Conversation

p-ranav
Copy link
Owner

@p-ranav p-ranav commented Nov 4, 2023

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

@p-ranav p-ranav self-assigned this Nov 4, 2023
@p-ranav p-ranav added the enhancement New feature or request label Nov 4, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-tidy found issue(s) with the introduced code (1/1)

include/argparse/argparse.hpp Outdated Show resolved Hide resolved
include/argparse/argparse.hpp Outdated Show resolved Hide resolved
include/argparse/argparse.hpp Show resolved Hide resolved
@p-ranav p-ranav merged commit 086c8f3 into master Nov 4, 2023
8 checks passed
@p-ranav p-ranav deleted the feature/221_mutex_args branch November 4, 2023 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant