Commit 7474a66ef6e26701e1b4be5428ab3e1ffada9c21

Authored by Matthew Limbinar
Committed by GitHub
1 parent a70771ae

Clarify positional argument docs (#335)

Showing 1 changed file with 24 additions and 5 deletions
README.md
... ... @@ -125,15 +125,34 @@ vector to the `help` function.
125 125  
126 126 ## Positional Arguments
127 127  
128   -Positional arguments can be optionally parsed into one or more options.
129   -To set up positional arguments, call
  128 +Positional arguments are those given without a preceding flag and can be used
  129 +alongside non-positional arguments. There may be multiple positional arguments,
  130 +and the final positional argument may be a container type to hold a list of all
  131 +remaining positionals.
  132 +
  133 +To set up positional arguments, first declare the options, then configure a
  134 +set of those arguments as positional like:
130 135  
131 136 ```cpp
132   -options.parse_positional({"first", "second", "last"})
  137 +options.add_options()
  138 + ("script", "The script file to execute", cxxopts::value<std::string>())
  139 + ("server", "The server to execute on", cxxopts::value<std::string>())
  140 + ("filenames", "The filename(s) to process", cxxopts::value<std::vector<std::string>>());
  141 +
  142 +options.parse_positional({"script", "server", "filenames"})
133 143 ```
134 144  
135   -where "last" should be the name of an option with a container type, and the
136   -others should have a single value.
  145 +Then parsing a set of arguments like:
  146 +~~~
  147 +my_script.py my_server.com file1.txt file2.txt file3.txt
  148 +~~~
  149 +will result in parsed arguments like the following table:
  150 +
  151 +| Field | Value |
  152 +| ------------- | ----------------------------------------- |
  153 +| `"script"` | `"my_script.py"` |
  154 +| `"server"` | `"my_server.com"` |
  155 +| `"filenames"` | `{"file1.txt", "file2.txt", "file3.txt"}` |
137 156  
138 157 ## Default and implicit values
139 158  
... ...