Skip to content

argparse

Compare
Choose a tag to compare
@p-ranav p-ranav released this 22 Jun 18:03
· 235 commits to master since this release

Merged pull request #125 - Improve nargs

Thanks @hokacci

You can now make a variable length list of arguments with the .nargs.
Below are some examples.

program.add_argument("--input_files")
  .nargs(1, 3);  // This accepts 1 to 3 arguments.

Some useful patterns are defined like "?", "*", "+" of argparse in Python.

program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::any);  // "*" in Python. This accepts any number of arguments including 0.
program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::at_least_one);  // "+" in Python. This accepts one or more number of arguments.
program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::optional);  // "?" in Python. This accepts an argument optionally.