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

Binding arg to a vector only allows for a single value #11

Closed
mattgodbolt opened this issue Oct 7, 2019 · 2 comments
Closed

Binding arg to a vector only allows for a single value #11

mattgodbolt opened this issue Oct 7, 2019 · 2 comments
Assignees
Projects

Comments

@mattgodbolt
Copy link

The following code:

int Main(int argc, const char* argv[]) {
  bool help = false;
  std::string out_path{};
  std::vector<std::string> input_paths;
  auto cli = lyra::cli_parser() | lyra::help(help) | lyra::arg(input_paths, "input...").required()("Input files, in gzip compressed CSV format");

  auto result = cli.parse({argc, argv});
  if (!result) {
    std::cerr << "Error in command line: " << result.errorMessage() << "\n";
    std::cerr << cli;
    return 1;
  }
...
}

when passed ./test a b c gives the error:

Error in command line: Unrecognized token: b

How might I set it to take any number of arguments? I saw the cardinality() call, but there's essentially no upper bound on the number of arguments. I could specify some arbitrary high limit, but I suspect I'm doing it wrong :)

@mattgodbolt
Copy link
Author

Update: removing the required and adding cardinality(1, std::numeric_limits<size_t>()) seems to do what I want. But it's not all that obvious :)

@grafikrobot
Copy link
Member

Would adding something like a at_least(1) method that does the right thing be a good enough solution?

@grafikrobot grafikrobot added this to To do in Development Oct 29, 2019
@grafikrobot grafikrobot self-assigned this Oct 30, 2019
@grafikrobot grafikrobot moved this from To do to In progress in Development Oct 30, 2019
Development automation moved this from In progress to Done Oct 30, 2019
@grafikrobot grafikrobot moved this from Done to Released in Development Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development
  
Released
Development

No branches or pull requests

2 participants