diff options
author | Matthew Limbinar <73853812+matthew-limbinar@users.noreply.github.com> | 2022-07-04 02:55:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 02:55:17 +0300 |
commit | 7474a66ef6e26701e1b4be5428ab3e1ffada9c21 (patch) | |
tree | 7681b00a3ecbdcb66a3ab6165388fe66b9c7d939 | |
parent | a70771ae894c787337e6393ff016c8e93e4237a3 (diff) |
Clarify positional argument docs (#335)
-rw-r--r-- | README.md | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -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 |