Skip to content

Commit

Permalink
Explain variable-length arguments in README
Browse files Browse the repository at this point in the history
  • Loading branch information
hokacci committed Jun 21, 2022
1 parent 7b5084c commit e44023f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,29 @@ catch (const std::runtime_error& err) {
auto query_point = program.get<std::vector<double>>("--query_point"); // {3.5, 4.7, 9.2}
```
You can also make a variable length list of arguments with the ```.nargs```.
Below are some examples.
```cpp
program.add_argument("--input_files")
.nargs(1, 3); // This accepts 1 to 3 arguments.
```

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

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

### Compound Arguments

Compound arguments are optional arguments that are combined and provided as a single argument. Example: ```ps -aux```
Expand Down

0 comments on commit e44023f

Please sign in to comment.