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 #277 #295

Merged
merged 4 commits into from
Oct 27, 2023
Merged

Closes #277 #295

merged 4 commits into from
Oct 27, 2023

Conversation

p-ranav
Copy link
Owner

@p-ranav p-ranav commented Oct 27, 2023

This PR adds in-built support for .choices() on arguments

#include "argparse.hpp"

int main(int argc, char* argv[]) {
  argparse::ArgumentParser program("test");

  program.add_argument("input")
    .default_value("baz")
    .choices("foo", "bar", "baz");

  try {
    program.parse_args(argc, argv);
  }
  catch (const std::exception& err) {
    std::cerr << err.what() << std::endl;
    std::cerr << program;
    std::exit(1);
  }

  auto input = program.get("input");
  std::cout << input << std::endl;
}
foo@bar:/home/dev/$ ./main fex
Invalid argument "fex" - allowed options: {foo, bar, baz}

@p-ranav p-ranav self-assigned this Oct 27, 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)

@p-ranav p-ranav merged commit b10afeb into master Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant