Clarify positional argument docs (#335)
This commit is contained in:
parent
a70771ae89
commit
7474a66ef6
29
README.md
29
README.md
@ -125,15 +125,34 @@ vector to the `help` function.
|
||||
|
||||
## Positional Arguments
|
||||
|
||||
Positional arguments can be optionally parsed into one or more options.
|
||||
To set up positional arguments, call
|
||||
Positional arguments are those given without a preceding flag and can be used
|
||||
alongside non-positional arguments. There may be multiple positional arguments,
|
||||
and the final positional argument may be a container type to hold a list of all
|
||||
remaining positionals.
|
||||
|
||||
To set up positional arguments, first declare the options, then configure a
|
||||
set of those arguments as positional like:
|
||||
|
||||
```cpp
|
||||
options.parse_positional({"first", "second", "last"})
|
||||
options.add_options()
|
||||
("script", "The script file to execute", cxxopts::value<std::string>())
|
||||
("server", "The server to execute on", cxxopts::value<std::string>())
|
||||
("filenames", "The filename(s) to process", cxxopts::value<std::vector<std::string>>());
|
||||
|
||||
options.parse_positional({"script", "server", "filenames"})
|
||||
```
|
||||
|
||||
where "last" should be the name of an option with a container type, and the
|
||||
others should have a single value.
|
||||
Then parsing a set of arguments like:
|
||||
~~~
|
||||
my_script.py my_server.com file1.txt file2.txt file3.txt
|
||||
~~~
|
||||
will result in parsed arguments like the following table:
|
||||
|
||||
| Field | Value |
|
||||
| ------------- | ----------------------------------------- |
|
||||
| `"script"` | `"my_script.py"` |
|
||||
| `"server"` | `"my_server.com"` |
|
||||
| `"filenames"` | `{"file1.txt", "file2.txt", "file3.txt"}` |
|
||||
|
||||
## Default and implicit values
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user