Commit 13becaddb657eacd090537719a669d66d393b8b2

Authored by Henry Schreiner
Committed by GitHub
1 parent 7b315782

Version 1.8 (#280)

* Version bump

* Update README

* Apply suggestions from code review

Co-Authored-By: Philip Top <top1@llnl.gov>

* Adding mark for deprecated items
1 -CLI11 1.7 Copyright (c) 2017-2019 University of Cincinnati, developed by Henry 1 +CLI11 1.8 Copyright (c) 2017-2019 University of Cincinnati, developed by Henry
2 Schreiner under NSF AWARD 1414736. All rights reserved. 2 Schreiner under NSF AWARD 1414736. All rights reserved.
3 3
4 Redistribution and use in source and binary forms of CLI11, with or without 4 Redistribution and use in source and binary forms of CLI11, with or without
5 modification, are permitted provided that the following conditions are met: 5 modification, are permitted provided that the following conditions are met:
6 6
7 1. Redistributions of source code must retain the above copyright notice, this 7 1. Redistributions of source code must retain the above copyright notice, this
8 - list of conditions and the following disclaimer. 8 + list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright notice, 9 2. Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation 10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution. 11 and/or other materials provided with the distribution.
README.md
@@ -33,15 +33,15 @@ CLI11 is a command line parser for C++11 and beyond that provides a rich feature @@ -33,15 +33,15 @@ CLI11 is a command line parser for C++11 and beyond that provides a rich feature
33 - [Option types](#option-types) 33 - [Option types](#option-types)
34 - [Example](#example) 34 - [Example](#example)
35 - [Option options](#option-options) 35 - [Option options](#option-options)
36 - - [Validators](#validators) ๐Ÿšง  
37 - - [Transforming Validators](#transforming-validators) ๐Ÿšง  
38 - - [Validator operations](#validator-operations) ๐Ÿšง  
39 - - [Custom Validators](#custom-validators) ๐Ÿšง  
40 - - [Querying Validators](#querying-validators) ๐Ÿšง  
41 - - [Getting Results](#getting-results) ๐Ÿšง 36 + - [Validators](#validators) ๐Ÿ†•
  37 + - [Transforming Validators](#transforming-validators) ๐Ÿ†•
  38 + - [Validator operations](#validator-operations) ๐Ÿ†•
  39 + - [Custom Validators](#custom-validators) ๐Ÿ†•
  40 + - [Querying Validators](#querying-validators) ๐Ÿ†•
  41 + - [Getting Results](#getting-results) ๐Ÿ†•
42 - [Subcommands](#subcommands) 42 - [Subcommands](#subcommands)
43 - [Subcommand options](#subcommand-options) 43 - [Subcommand options](#subcommand-options)
44 - - [Option groups](#option-groups) ๐Ÿšง 44 + - [Option groups](#option-groups) ๐Ÿ†•
45 - [Callbacks](#callbacks) 45 - [Callbacks](#callbacks)
46 - [Configuration file](#configuration-file) 46 - [Configuration file](#configuration-file)
47 - [Inheriting defaults](#inheriting-defaults) 47 - [Inheriting defaults](#inheriting-defaults)
@@ -55,7 +55,7 @@ CLI11 is a command line parser for C++11 and beyond that provides a rich feature @@ -55,7 +55,7 @@ CLI11 is a command line parser for C++11 and beyond that provides a rich feature
55 - [Contribute](#contribute) 55 - [Contribute](#contribute)
56 - [License](#license) 56 - [License](#license)
57 57
58 -Features that were added in the last released major version are marked with "๐Ÿ†•". Features only available in master are marked with "๐Ÿšง". 58 +Features that were added in the last released major version are marked with "๐Ÿ†•". Features only available in master are marked with "๐Ÿ†•".
59 59
60 ## Background 60 ## Background
61 61
@@ -191,14 +191,14 @@ While all options internally are the same type, there are several ways to add an @@ -191,14 +191,14 @@ While all options internally are the same type, there are several ways to add an
191 191
192 ```cpp 192 ```cpp
193 // Add options 193 // Add options
194 -app.add_option(option_name, help_str="") // ๐Ÿšง 194 +app.add_option(option_name, help_str="") // ๐Ÿ†•
195 195
196 app.add_option(option_name, 196 app.add_option(option_name,
197 - variable_to_bind_to, // bool, int, float, vector, ๐Ÿšง enum, or string-like, or anything with a defined conversion from a string 197 + variable_to_bind_to, // bool, int, float, vector, ๐Ÿ†• enum, or string-like, or anything with a defined conversion from a string
198 help_string="") 198 help_string="")
199 199
200 app.add_option_function<type>(option_name, 200 app.add_option_function<type>(option_name,
201 - function <void(const type &value)>, // ๐Ÿšง int, bool, float, enum, vector, or string-like, or anything with a defined conversion from a string 201 + function <void(const type &value)>, // ๐Ÿ†• int, bool, float, enum, vector, or string-like, or anything with a defined conversion from a string
202 help_string="") 202 help_string="")
203 203
204 app.add_complex(... // Special case: support for complex numbers 204 app.add_complex(... // Special case: support for complex numbers
@@ -208,42 +208,42 @@ app.add_flag(option_name, @@ -208,42 +208,42 @@ app.add_flag(option_name,
208 help_string="") 208 help_string="")
209 209
210 app.add_flag(option_name, 210 app.add_flag(option_name,
211 - variable_to_bind_to, // bool, int, ๐Ÿšง float, ๐Ÿšง vector, ๐Ÿšง enum, or ๐Ÿšง string-like, or ๐Ÿšง anything with a defined conversion from a string 211 + variable_to_bind_to, // bool, int, ๐Ÿ†• float, ๐Ÿ†• vector, ๐Ÿ†• enum, or ๐Ÿ†• string-like, or ๐Ÿ†• anything with a defined conversion from a string
212 help_string="") 212 help_string="")
213 213
214 -app.add_flag_function(option_name, // ๐Ÿšง 214 +app.add_flag_function(option_name, // ๐Ÿ†•
215 function <void(int64_t count)>, 215 function <void(int64_t count)>,
216 help_string="") 216 help_string="")
217 217
218 -app.add_flag_callback(option_name,function<void(void)>,help_string="") // ๐Ÿšง 218 +app.add_flag_callback(option_name,function<void(void)>,help_string="") // ๐Ÿ†•
219 219
220 // Add subcommands 220 // Add subcommands
221 App* subcom = app.add_subcommand(name, description); 221 App* subcom = app.add_subcommand(name, description);
222 222
223 -Option_group *app.add_option_group(name,description); // ๐Ÿšง 223 +Option_group *app.add_option_group(name,description); // ๐Ÿ†•
224 224
225 -// ๐Ÿšง All add_*set* methods deprecated in CLI11 1.8 - use ->transform(CLI::IsMember) instead 225 +// โš ๏ธ All add_*set* methods deprecated in CLI11 1.8 - use ->transform(CLI::IsMember) instead
226 -app.add_set(option_name, 226 -app.add_set(option_name,
227 - variable_to_bind_to, // Same type as stored by set 227 - variable_to_bind_to, // Same type as stored by set
228 - set_of_possible_options, // Set will be copied, ignores changes 228 - set_of_possible_options, // Set will be copied, ignores changes
229 - help_string="") 229 - help_string="")
230 --app.add_mutable_set(... // ๐Ÿ†• Set can change later, keeps reference 230 +-app.add_mutable_set(... // Set can change later, keeps reference
231 -app.add_set_ignore_case(... // String only 231 -app.add_set_ignore_case(... // String only
232 --app.add_mutable_set_ignore_case(... // ๐Ÿ†• String only  
233 --app.add_set_ignore_underscore(... // ๐Ÿ†• String only  
234 --app.add_mutable_set_ignore_underscore(... // ๐Ÿ†• String only  
235 --app.add_set_ignore_case_underscore(... // ๐Ÿ†• String only  
236 --app.add_mutable_set_ignore_case_underscore(... // ๐Ÿ†• String only 232 +-app.add_mutable_set_ignore_case(... // String only
  233 +-app.add_set_ignore_underscore(... // String only
  234 +-app.add_mutable_set_ignore_underscore(... // String only
  235 +-app.add_set_ignore_case_underscore(... // String only
  236 +-app.add_mutable_set_ignore_case_underscore(... // String only
237 ``` 237 ```
238 238
239 -An option name must start with a alphabetic character, underscore, a number ๐Ÿšง, '?' ๐Ÿšง, or '@' ๐Ÿšง. For long options, after the first character '.', and '-' are also valid characters. For the `add_flag*` functions '{' has special meaning. Names are given as a comma separated string, with the dash or dashes. An option or flag can have as many names as you want, and afterward, using `count`, you can use any of the names, with dashes as needed, to count the options. One of the names is allowed to be given without proceeding dash(es); if present the option is a positional option, and that name will be used on the help line for its positional form. 239 +An option name must start with a alphabetic character, underscore, a number ๐Ÿ†•, '?' ๐Ÿ†•, or '@' ๐Ÿ†•. For long options, after the first character '.', and '-' are also valid characters. For the `add_flag*` functions '{' has special meaning. Names are given as a comma separated string, with the dash or dashes. An option or flag can have as many names as you want, and afterward, using `count`, you can use any of the names, with dashes as needed, to count the options. One of the names is allowed to be given without proceeding dash(es); if present the option is a positional option, and that name will be used on the help line for its positional form.
240 240
241 The `add_option_function<type>(...` function will typically require the template parameter be given unless a `std::function` object with an exact match is passed. The type can be any type supported by the `add_option` function. The function should throw an error (`CLI::ConversionError` or `CLI::ValidationError` possibly) if the value is not valid. 241 The `add_option_function<type>(...` function will typically require the template parameter be given unless a `std::function` object with an exact match is passed. The type can be any type supported by the `add_option` function. The function should throw an error (`CLI::ConversionError` or `CLI::ValidationError` possibly) if the value is not valid.
242 242
243 -๐Ÿšง Flag options specified through the `add_flag*` functions allow a syntax for the option names to default particular options to a false value or any other value if some flags are passed. For example: 243 +๐Ÿ†• Flag options specified through the `add_flag*` functions allow a syntax for the option names to default particular options to a false value or any other value if some flags are passed. For example:
244 244
245 ```cpp 245 ```cpp
246 -app.add_flag("--flag,!--no-flag",result,"help for flag"); // ๐Ÿšง 246 +app.add_flag("--flag,!--no-flag",result,"help for flag"); // ๐Ÿ†•
247 ``` 247 ```
248 248
249 specifies that if `--flag` is passed on the command line result will be true or contain a value of 1. If `--no-flag` is 249 specifies that if `--flag` is passed on the command line result will be true or contain a value of 1. If `--no-flag` is
@@ -252,10 +252,12 @@ alternative form of the syntax is more explicit: `&quot;--flag,--no-flag{false}&quot;`; th @@ -252,10 +252,12 @@ alternative form of the syntax is more explicit: `&quot;--flag,--no-flag{false}&quot;`; th
252 example. This also works for short form options `"-f,!-n"` or `"-f,-n{false}"`. If `variable_to_bind_to` is anything but an integer value the 252 example. This also works for short form options `"-f,!-n"` or `"-f,-n{false}"`. If `variable_to_bind_to` is anything but an integer value the
253 default behavior is to take the last value given, while if `variable_to_bind_to` is an integer type the behavior will be to sum 253 default behavior is to take the last value given, while if `variable_to_bind_to` is an integer type the behavior will be to sum
254 all the given arguments and return the result. This can be modified if needed by changing the `multi_option_policy` on each flag (this is not inherited). 254 all the given arguments and return the result. This can be modified if needed by changing the `multi_option_policy` on each flag (this is not inherited).
255 -The default value can be any value. For example if you wished to define a numerical flag 255 +The default value can be any value. For example if you wished to define a numerical flag:
  256 +
256 ```cpp 257 ```cpp
257 -app.add_flag("-1{1},-2{2},-3{3}",result,"numerical flag") // ๐Ÿšง 258 +app.add_flag("-1{1},-2{2},-3{3}",result,"numerical flag") // ๐Ÿ†•
258 ``` 259 ```
  260 +
259 using any of those flags on the command line will result in the specified number in the output. Similar things can be done for string values, and enumerations, as long as the default value can be converted to the given type. 261 using any of those flags on the command line will result in the specified number in the output. Similar things can be done for string values, and enumerations, as long as the default value can be converted to the given type.
260 262
261 263
@@ -269,7 +271,9 @@ On a compiler that supports C++17&#39;s `__has_include`, you can also use `std::opti @@ -269,7 +271,9 @@ On a compiler that supports C++17&#39;s `__has_include`, you can also use `std::opti
269 - `"this"` Can only be passed positionally 271 - `"this"` Can only be passed positionally
270 - `"-a,-b,-c"` No limit to the number of non-positional option names 272 - `"-a,-b,-c"` No limit to the number of non-positional option names
271 273
272 -The add commands return a pointer to an internally stored `Option`. If you set the final argument to true, the default value is captured and printed on the command line with the help flag. This option can be used directly to check for the count (`->count()`) after parsing to avoid a string based lookup. 274 +The add commands return a pointer to an internally stored `Option`.
  275 +This option can be used directly to check for the count (`->count()`) after parsing to avoid a string based lookup.
  276 +โš ๏ธ Deprecated: The `add_*` commands have a final argument than can be set to true, which causes the default value to be captured and printed on the command line with the help flag. Since CLI11 1.8, you can simply add `->capture_default_str()`.
273 277
274 #### Option options 278 #### Option options
275 279
@@ -284,20 +288,20 @@ Before parsing, you can set the following options: @@ -284,20 +288,20 @@ Before parsing, you can set the following options:
284 - `->envname(name)`: Gets the value from the environment if present and not passed on the command line. 288 - `->envname(name)`: Gets the value from the environment if present and not passed on the command line.
285 - `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden). 289 - `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden).
286 - `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments). 290 - `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments).
287 -- `->ignore_underscore()`: ๐Ÿ†• Ignore any underscores in the options names (also works on subcommands, does not affect arguments). For example "option_one" will match with "optionone". This does not apply to short form options since they only have one character  
288 -- `->disable_flag_override()`: ๐Ÿšง From the command line long form flag options can be assigned a value on the command line using the `=` notation `--flag=value`. If this behavior is not desired, the `disable_flag_override()` disables it and will generate an exception if it is done on the command line. The `=` does not work with short form flag options.  
289 -- `->delimiter(char)`: ๐Ÿšง allows specification of a custom delimiter for separating single arguments into vector arguments, for example specifying `->delimiter(',')` on an option would result in `--opt=1,2,3` producing 3 elements of a vector and the equivalent of --opt 1 2 3 assuming opt is a vector value.  
290 -- `->description(str)`: ๐Ÿ†• Set/change the description. 291 +- `->ignore_underscore()`: Ignore any underscores in the options names (also works on subcommands, does not affect arguments). For example "option_one" will match with "optionone". This does not apply to short form options since they only have one character
  292 +- `->disable_flag_override()`: ๐Ÿ†• From the command line long form flag options can be assigned a value on the command line using the `=` notation `--flag=value`. If this behavior is not desired, the `disable_flag_override()` disables it and will generate an exception if it is done on the command line. The `=` does not work with short form flag options.
  293 +- `->delimiter(char)`: ๐Ÿ†• allows specification of a custom delimiter for separating single arguments into vector arguments, for example specifying `->delimiter(',')` on an option would result in `--opt=1,2,3` producing 3 elements of a vector and the equivalent of --opt 1 2 3 assuming opt is a vector value.
  294 +- `->description(str)`: Set/change the description.
291 - `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`, and `->join()`. This will only affect options expecting 1 argument or bool flags (which do not inherit their default but always start with a specific policy). 295 - `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`, and `->join()`. This will only affect options expecting 1 argument or bool flags (which do not inherit their default but always start with a specific policy).
292 -- `->check(std::string(const std::string &), validator_name="",validator_description="")`: ๐Ÿšง Define a check function. The function should return a non empty string with the error message if the check fails  
293 -- `->check(Validator)`:๐Ÿšง Use a Validator object to do the check see [Validators](#validators) for a description of available Validators and how to create new ones. 296 +- `->check(std::string(const std::string &), validator_name="",validator_description="")`: ๐Ÿ†• Define a check function. The function should return a non empty string with the error message if the check fails
  297 +- `->check(Validator)`:๐Ÿ†• Use a Validator object to do the check see [Validators](#validators) for a description of available Validators and how to create new ones.
294 - `->transform(std::string(std::string &), validator_name="",validator_description=")`: Converts the input string into the output string, in-place in the parsed options. 298 - `->transform(std::string(std::string &), validator_name="",validator_description=")`: Converts the input string into the output string, in-place in the parsed options.
295 - `->transform(Validator)`: uses a Validator object to do the transformation see [Validators](#validators) for a description of available Validators and how to create new ones. 299 - `->transform(Validator)`: uses a Validator object to do the transformation see [Validators](#validators) for a description of available Validators and how to create new ones.
296 - `->each(void(const std::string &)>`: Run this function on each value received, as it is received. It should throw a `ValidationError` if an error is encountered. 300 - `->each(void(const std::string &)>`: Run this function on each value received, as it is received. It should throw a `ValidationError` if an error is encountered.
297 - `->configurable(false)`: Disable this option from being in a configuration file. 301 - `->configurable(false)`: Disable this option from being in a configuration file.
298 - `->capture_default_str()`: ๐Ÿšง Store the current value attached and display it in the help string.  
299 - `->default_function(std::string())`: ๐Ÿšง Advanced: Change the function that `capture_default_str()` uses.  
300 - `->always_capture_default()`: ๐Ÿšง Always run `capture_default_str()` when creating new options. Only useful on an App's `option_defaults`. 302 + `->capture_default_str()`: ๐Ÿ†• Store the current value attached and display it in the help string.
  303 + `->default_function(std::string())`: ๐Ÿ†• Advanced: Change the function that `capture_default_str()` uses.
  304 + `->always_capture_default()`: ๐Ÿ†• Always run `capture_default_str()` when creating new options. Only useful on an App's `option_defaults`.
301 305
302 306
303 These options return the `Option` pointer, so you can chain them together, and even skip storing the pointer entirely. The `each` function takes any function that has the signature `void(const std::string&)`; it should throw a `ValidationError` when validation fails. The help message will have the name of the parent option prepended. Since `each`, `check` and `transform` use the same underlying mechanism, you can chain as many as you want, and they will be executed in order. Operations added through `transform` are executed first in reverse order of addition, and `check` and `each` are run following the transform functions in order of addition. If you just want to see the unconverted values, use `.results()` to get the `std::vector<std::string>` of results. 307 These options return the `Option` pointer, so you can chain them together, and even skip storing the pointer entirely. The `each` function takes any function that has the signature `void(const std::string&)`; it should throw a `ValidationError` when validation fails. The help message will have the name of the parent option prepended. Since `each`, `check` and `transform` use the same underlying mechanism, you can chain as many as you want, and they will be executed in order. Operations added through `transform` are executed first in reverse order of addition, and `check` and `each` are run following the transform functions in order of addition. If you just want to see the unconverted values, use `.results()` to get the `std::vector<std::string>` of results.
@@ -310,24 +314,24 @@ On the command line, options can be given as: @@ -310,24 +314,24 @@ On the command line, options can be given as:
310 - `-ffilename` (no space required) 314 - `-ffilename` (no space required)
311 - `-abcf filename` (flags and option can be combined) 315 - `-abcf filename` (flags and option can be combined)
312 - `--long` (long flag) 316 - `--long` (long flag)
313 -- `--long_flag=true` (long flag with equals to override default value) ๐Ÿšง 317 +- `--long_flag=true` (long flag with equals to override default value) ๐Ÿ†•
314 - `--file filename` (space) 318 - `--file filename` (space)
315 - `--file=filename` (equals) 319 - `--file=filename` (equals)
316 320
317 -๐Ÿ†• If `allow_windows_style_options()` is specified in the application or subcommand options can also be given as: 321 +If `allow_windows_style_options()` is specified in the application or subcommand options can also be given as:
318 - `/a` (flag) 322 - `/a` (flag)
319 - `/f filename` (option) 323 - `/f filename` (option)
320 - `/long` (long flag) 324 - `/long` (long flag)
321 - `/file filename` (space) 325 - `/file filename` (space)
322 - `/file:filename` (colon) 326 - `/file:filename` (colon)
323 -- `/long_flag:false` (long flag with : to override the default value) ๐Ÿšง 327 +- `/long_flag:false` (long flag with : to override the default value) ๐Ÿ†•
324 = Windows style options do not allow combining short options or values not separated from the short option like with `-` options 328 = Windows style options do not allow combining short options or values not separated from the short option like with `-` options
325 329
326 -๐Ÿšง Long flag options may be given with an `=<value>` to allow specifying a false value, or some other value to the flag. See [config files](#configuration-file) for details on the values supported. NOTE: only the `=` or `:` for windows-style options may be used for this, using a space will result in the argument being interpreted as a positional argument. This syntax can override the default values, and can be disabled by using `disable_flag_override()`. 330 +๐Ÿ†• Long flag options may be given with an `=<value>` to allow specifying a false value, or some other value to the flag. See [config files](#configuration-file) for details on the values supported. NOTE: only the `=` or `:` for windows-style options may be used for this, using a space will result in the argument being interpreted as a positional argument. This syntax can override the default values, and can be disabled by using `disable_flag_override()`.
327 331
328 Extra positional arguments will cause the program to exit, so at least one positional option with a vector is recommended if you want to allow extraneous arguments. 332 Extra positional arguments will cause the program to exit, so at least one positional option with a vector is recommended if you want to allow extraneous arguments.
329 If you set `.allow_extras()` on the main `App`, you will not get an error. You can access the missing options using `remaining` (if you have subcommands, `app.remaining(true)` will get all remaining options, subcommands included). 333 If you set `.allow_extras()` on the main `App`, you will not get an error. You can access the missing options using `remaining` (if you have subcommands, `app.remaining(true)` will get all remaining options, subcommands included).
330 -If the remaining arguments are to processed by another `App` then the function `remaining_for_passthrough()` ๐Ÿšง can be used to get the remaining arguments in reverse order such that `app.parse(vector)` works directly and could even be used inside a subcommand callback. 334 +If the remaining arguments are to processed by another `App` then the function `remaining_for_passthrough()` ๐Ÿ†• can be used to get the remaining arguments in reverse order such that `app.parse(vector)` works directly and could even be used inside a subcommand callback.
331 335
332 You can access a vector of pointers to the parsed options in the original order using `parse_order()`. 336 You can access a vector of pointers to the parsed options in the original order using `parse_order()`.
333 If `--` is present in the command line that does not end an unlimited option, then 337 If `--` is present in the command line that does not end an unlimited option, then
@@ -338,20 +342,20 @@ Validators are structures to check or modify inputs, they can be used to verify @@ -338,20 +342,20 @@ Validators are structures to check or modify inputs, they can be used to verify
338 342
339 CLI11 has several Validators built-in that perform some common checks 343 CLI11 has several Validators built-in that perform some common checks
340 344
341 -- `CLI::IsMember(...)`: ๐Ÿšง Require an option be a member of a given set. See [Transforming Validators](#transforming-validators) for more details.  
342 -- `CLI::Transformer(...)`: ๐Ÿšง Modify the input using a map. See [Transforming Validators](#transforming-validators) for more details.  
343 -- `CLI::CheckedTransformer(...)`: ๐Ÿšง Modify the input using a map, and require that the input is either in the set or already one of the outputs of the set. See [Transforming Validators](#transforming-validators) for more details.  
344 -- `CLI::AsNumberWithUnit(...)`:๐Ÿšง Modify the `<NUMBER> <UNIT>` pair by matching the unit and multiplying the number by the corresponding factor. It can be used as a base for transformers, that accept things like size values (`1 KB`) or durations (`0.33 ms`).  
345 -- `CLI::AsSizeValue(...)`: ๐Ÿšง Convert inputs like `100b`, `42 KB`, `101 Mb`, `11 Mib` to absolute values. `KB` can be configured to be interpreted as 10^3 or 2^10. 345 +- `CLI::IsMember(...)`: ๐Ÿ†• Require an option be a member of a given set. See [Transforming Validators](#transforming-validators) for more details.
  346 +- `CLI::Transformer(...)`: ๐Ÿ†• Modify the input using a map. See [Transforming Validators](#transforming-validators) for more details.
  347 +- `CLI::CheckedTransformer(...)`: ๐Ÿ†• Modify the input using a map, and require that the input is either in the set or already one of the outputs of the set. See [Transforming Validators](#transforming-validators) for more details.
  348 +- `CLI::AsNumberWithUnit(...)`:๐Ÿ†• Modify the `<NUMBER> <UNIT>` pair by matching the unit and multiplying the number by the corresponding factor. It can be used as a base for transformers, that accept things like size values (`1 KB`) or durations (`0.33 ms`).
  349 +- `CLI::AsSizeValue(...)`: ๐Ÿ†• Convert inputs like `100b`, `42 KB`, `101 Mb`, `11 Mib` to absolute values. `KB` can be configured to be interpreted as 10^3 or 2^10.
346 - `CLI::ExistingFile`: Requires that the file exists if given. 350 - `CLI::ExistingFile`: Requires that the file exists if given.
347 - `CLI::ExistingDirectory`: Requires that the directory exists. 351 - `CLI::ExistingDirectory`: Requires that the directory exists.
348 - `CLI::ExistingPath`: Requires that the path (file or directory) exists. 352 - `CLI::ExistingPath`: Requires that the path (file or directory) exists.
349 - `CLI::NonexistentPath`: Requires that the path does not exist. 353 - `CLI::NonexistentPath`: Requires that the path does not exist.
350 - `CLI::Range(min,max)`: Requires that the option be between min and max (make sure to use floating point if needed). Min defaults to 0. 354 - `CLI::Range(min,max)`: Requires that the option be between min and max (make sure to use floating point if needed). Min defaults to 0.
351 -- `CLI::Bounded(min,max)`: ๐Ÿšง Modify the input such that it is always between min and max (make sure to use floating point if needed). Min defaults to 0. Will produce an error if conversion is not possible.  
352 -- `CLI::PositiveNumber`: ๐Ÿšง Requires the number be greater or equal to 0  
353 -- `CLI::Number`: ๐Ÿšง Requires the input be a number.  
354 -- `CLI::ValidIPV4`: ๐Ÿšง Requires that the option be a valid IPv4 string e.g. `'255.255.255.255'`, `'10.1.1.7'`. 355 +- `CLI::Bounded(min,max)`: ๐Ÿ†• Modify the input such that it is always between min and max (make sure to use floating point if needed). Min defaults to 0. Will produce an error if conversion is not possible.
  356 +- `CLI::PositiveNumber`: ๐Ÿ†• Requires the number be greater or equal to 0
  357 +- `CLI::Number`: ๐Ÿ†• Requires the input be a number.
  358 +- `CLI::ValidIPV4`: ๐Ÿ†• Requires that the option be a valid IPv4 string e.g. `'255.255.255.255'`, `'10.1.1.7'`.
355 359
356 These Validators can be used by simply passing the name into the `check` or `transform` methods on an option 360 These Validators can be used by simply passing the name into the `check` or `transform` methods on an option
357 361
@@ -360,7 +364,7 @@ These Validators can be used by simply passing the name into the `check` or `tra @@ -360,7 +364,7 @@ These Validators can be used by simply passing the name into the `check` or `tra
360 ->check(CLI::Range(0,10)); 364 ->check(CLI::Range(0,10));
361 ``` 365 ```
362 366
363 -Validators can be merged using `&` and `|` and inverted using `!` ๐Ÿšง. For example: 367 +Validators can be merged using `&` and `|` and inverted using `!` ๐Ÿ†•. For example:
364 368
365 ```cpp 369 ```cpp
366 ->check(CLI::Range(0,10)|CLI::Range(20,30)); 370 ->check(CLI::Range(0,10)|CLI::Range(20,30));
@@ -376,8 +380,8 @@ will produce a check for a number less than 0. @@ -376,8 +380,8 @@ will produce a check for a number less than 0.
376 380
377 ##### Transforming Validators 381 ##### Transforming Validators
378 There are a few built in Validators that let you transform values if used with the `transform` function. If they also do some checks then they can be used `check` but some may do nothing in that case. 382 There are a few built in Validators that let you transform values if used with the `transform` function. If they also do some checks then they can be used `check` but some may do nothing in that case.
379 - * ๐Ÿšง `CLI::Bounded(min,max)` will bound values between min and max and values outside of that range are limited to min or max, it will fail if the value cannot be converted and produce a `ValidationError`  
380 - * ๐Ÿšง The `IsMember` Validator lets you specify a set of predefined options. You can pass any container or copyable pointer (including `std::shared_ptr`) to a container to this validator; the container just needs to be iterable and have a `::value_type`. The key type should be convertible from a string, You can use an initializer list directly if you like. If you need to modify the set later, the pointer form lets you do that; the type message and check will correctly refer to the current version of the set. The container passed in can be a set, vector, or a map like structure. If used in the `transform` method the output value will be the matching key as it could be modified by filters. 383 + * ๐Ÿ†• `CLI::Bounded(min,max)` will bound values between min and max and values outside of that range are limited to min or max, it will fail if the value cannot be converted and produce a `ValidationError`
  384 + * ๐Ÿ†• The `IsMember` Validator lets you specify a set of predefined options. You can pass any container or copyable pointer (including `std::shared_ptr`) to a container to this validator; the container just needs to be iterable and have a `::value_type`. The key type should be convertible from a string, You can use an initializer list directly if you like. If you need to modify the set later, the pointer form lets you do that; the type message and check will correctly refer to the current version of the set. The container passed in can be a set, vector, or a map like structure. If used in the `transform` method the output value will be the matching key as it could be modified by filters.
381 After specifying a set of options, you can also specify "filter" functions of the form `T(T)`, where `T` is the type of the values. The most common choices probably will be `CLI::ignore_case` an `CLI::ignore_underscore`, and `CLI::ignore_space`. These all work on strings but it is possible to define functions that work on other types. 385 After specifying a set of options, you can also specify "filter" functions of the form `T(T)`, where `T` is the type of the values. The most common choices probably will be `CLI::ignore_case` an `CLI::ignore_underscore`, and `CLI::ignore_space`. These all work on strings but it is possible to define functions that work on other types.
382 Here are some examples 386 Here are some examples
383 of `IsMember`: 387 of `IsMember`:
@@ -387,7 +391,7 @@ of `IsMember`: @@ -387,7 +391,7 @@ of `IsMember`:
387 * `CLI::IsMember(std::set<int>({2,3,4}))`: Most containers and types work; you just need `std::begin`, `std::end`, and `::value_type`. 391 * `CLI::IsMember(std::set<int>({2,3,4}))`: Most containers and types work; you just need `std::begin`, `std::end`, and `::value_type`.
388 * `CLI::IsMember(std::map<std::string, TYPE>({{"one", 1}, {"two", 2}}))`: You can use maps; in `->transform()` these replace the matched value with the matched key. The value member of the map is not used in `IsMember`, so it can be any type. 392 * `CLI::IsMember(std::map<std::string, TYPE>({{"one", 1}, {"two", 2}}))`: You can use maps; in `->transform()` these replace the matched value with the matched key. The value member of the map is not used in `IsMember`, so it can be any type.
389 * `auto p = std::make_shared<std::vector<std::string>>(std::initializer_list<std::string>("one", "two")); CLI::IsMember(p)`: You can modify `p` later. 393 * `auto p = std::make_shared<std::vector<std::string>>(std::initializer_list<std::string>("one", "two")); CLI::IsMember(p)`: You can modify `p` later.
390 -* ๐Ÿšง The `Transformer` and `CheckedTransformer` Validators transform one value into another. Any container or copyable pointer (including `std::shared_ptr`) to a container that generates pairs of values can be passed to these `Validator's`; the container just needs to be iterable and have a `::value_type` that consists of pairs. The key type should be convertible from a string, and the value type should be convertible to a string You can use an initializer list directly if you like. If you need to modify the map later, the pointer form lets you do that; the description message will correctly refer to the current version of the map. `Transformer` does not do any checking so values not in the map are ignored. `CheckedTransformer` takes an extra step of verifying that the value is either one of the map key values, in which case it is transformed, or one of the expected output values, and if not will generate a `ValidationError`. A Transformer placed using `check` will not do anything. 394 +* ๐Ÿ†• The `Transformer` and `CheckedTransformer` Validators transform one value into another. Any container or copyable pointer (including `std::shared_ptr`) to a container that generates pairs of values can be passed to these `Validator's`; the container just needs to be iterable and have a `::value_type` that consists of pairs. The key type should be convertible from a string, and the value type should be convertible to a string You can use an initializer list directly if you like. If you need to modify the map later, the pointer form lets you do that; the description message will correctly refer to the current version of the map. `Transformer` does not do any checking so values not in the map are ignored. `CheckedTransformer` takes an extra step of verifying that the value is either one of the map key values, in which case it is transformed, or one of the expected output values, and if not will generate a `ValidationError`. A Transformer placed using `check` will not do anything.
391 After specifying a map of options, you can also specify "filter" just like in `CLI::IsMember`. 395 After specifying a map of options, you can also specify "filter" just like in `CLI::IsMember`.
392 Here are some examples (`Transformer` and `CheckedTransformer` are interchangeable in the examples) 396 Here are some examples (`Transformer` and `CheckedTransformer` are interchangeable in the examples)
393 of `Transformer`: 397 of `Transformer`:
@@ -400,7 +404,7 @@ of `Transformer`: @@ -400,7 +404,7 @@ of `Transformer`:
400 404
401 NOTES: If the container used in `IsMember`, `Transformer`, or `CheckedTransformer` has a `find` function like `std::unordered_map` or `std::map` then that function is used to do the searching. If it does not have a `find` function a linear search is performed. If there are filters present, the fast search is performed first, and if that fails a linear search with the filters on the key values is performed. 405 NOTES: If the container used in `IsMember`, `Transformer`, or `CheckedTransformer` has a `find` function like `std::unordered_map` or `std::map` then that function is used to do the searching. If it does not have a `find` function a linear search is performed. If there are filters present, the fast search is performed first, and if that fails a linear search with the filters on the key values is performed.
402 406
403 -##### Validator operations ๐Ÿšง 407 +##### Validator operations ๐Ÿ†•
404 Validators are copyable and have a few operations that can be performed on them to alter settings. Most of the built in Validators have a default description that is displayed in the help. This can be altered via `.description(validator_description)`. 408 Validators are copyable and have a few operations that can be performed on them to alter settings. Most of the built in Validators have a default description that is displayed in the help. This can be altered via `.description(validator_description)`.
405 The name of a Validator, which is useful for later reference from the `get_validator(name)` method of an `Option` can be set via `.name(validator_name)` 409 The name of a Validator, which is useful for later reference from the `get_validator(name)` method of an `Option` can be set via `.name(validator_name)`
406 The operation function of a Validator can be set via 410 The operation function of a Validator can be set via
@@ -410,48 +414,57 @@ All the functions return a Validator reference allowing them to be chained. For @@ -410,48 +414,57 @@ All the functions return a Validator reference allowing them to be chained. For
410 ```cpp 414 ```cpp
411 opt->check(CLI::Range(10,20).description("range is limited to sensible values").active(false).name("range")); 415 opt->check(CLI::Range(10,20).description("range is limited to sensible values").active(false).name("range"));
412 ``` 416 ```
  417 +
413 will specify a check on an option with a name "range", but deactivate it for the time being. 418 will specify a check on an option with a name "range", but deactivate it for the time being.
414 The check can later be activated through 419 The check can later be activated through
  420 +
415 ```cpp 421 ```cpp
416 opt->get_validator("range")->active(); 422 opt->get_validator("range")->active();
417 ``` 423 ```
418 424
419 -##### Custom Validators ๐Ÿšง 425 +##### Custom Validators ๐Ÿ†•
420 426
421 A validator object with a custom function can be created via 427 A validator object with a custom function can be created via
  428 +
422 ```cpp 429 ```cpp
423 CLI::Validator(std::function<std::string(std::string &)>,validator_description,validator_name=""); 430 CLI::Validator(std::function<std::string(std::string &)>,validator_description,validator_name="");
424 ``` 431 ```
  432 +
425 or if the operation function is set later they can be created with 433 or if the operation function is set later they can be created with
  434 +
426 ```cpp 435 ```cpp
427 CLI::Validator(validator_description); 436 CLI::Validator(validator_description);
428 ``` 437 ```
429 438
430 It is also possible to create a subclass of `CLI::Validator`, in which case it can also set a custom description function, and operation function. 439 It is also possible to create a subclass of `CLI::Validator`, in which case it can also set a custom description function, and operation function.
431 440
432 -##### Querying Validators ๐Ÿšง 441 +##### Querying Validators ๐Ÿ†•
  442 +
433 Once loaded into an Option, a pointer to a named Validator can be retrieved via 443 Once loaded into an Option, a pointer to a named Validator can be retrieved via
  444 +
434 ```cpp 445 ```cpp
435 opt->get_validator(name); 446 opt->get_validator(name);
436 ``` 447 ```
  448 +
437 This will retrieve a Validator with the given name or throw a `CLI::OptionNotFound` error. If no name is given or name is empty the first unnamed Validator will be returned or the first Validator if there is only one. 449 This will retrieve a Validator with the given name or throw a `CLI::OptionNotFound` error. If no name is given or name is empty the first unnamed Validator will be returned or the first Validator if there is only one.
438 450
439 Validators have a few functions to query the current values 451 Validators have a few functions to query the current values
440 - * `get_description()`: ๐Ÿšง Will return a description string  
441 - * `get_name()`: ๐Ÿšง Will return the Validator name  
442 - * `get_active()`: ๐Ÿšง Will return the current active state, true if the Validator is active.  
443 - * `get_modifying()`: ๐Ÿšง Will return true if the Validator is allowed to modify the input, this can be controlled via the `non_modifying()` ๐Ÿšง method, though it is recommended to let `check` and `transform` option methods manipulate it if needed. 452 + * `get_description()`: ๐Ÿ†• Will return a description string
  453 + * `get_name()`: ๐Ÿ†• Will return the Validator name
  454 + * `get_active()`: ๐Ÿ†• Will return the current active state, true if the Validator is active.
  455 + * `get_modifying()`: ๐Ÿ†• Will return true if the Validator is allowed to modify the input, this can be controlled via the `non_modifying()` ๐Ÿ†• method, though it is recommended to let `check` and `transform` option methods manipulate it if needed.
444 456
445 #### Getting results 457 #### Getting results
  458 +
446 In most cases, the fastest and easiest way is to return the results through a callback or variable specified in one of the `add_*` functions. But there are situations where this is not possible or desired. For these cases the results may be obtained through one of the following functions. Please note that these functions will do any type conversions and processing during the call so should not used in performance critical code: 459 In most cases, the fastest and easiest way is to return the results through a callback or variable specified in one of the `add_*` functions. But there are situations where this is not possible or desired. For these cases the results may be obtained through one of the following functions. Please note that these functions will do any type conversions and processing during the call so should not used in performance critical code:
447 460
448 - `results()`: Retrieves a vector of strings with all the results in the order they were given. 461 - `results()`: Retrieves a vector of strings with all the results in the order they were given.
449 -- `results(variable_to_bind_to)`: ๐Ÿšง Gets the results according to the MultiOptionPolicy and converts them just like the `add_option_function` with a variable.  
450 -- `Value=as<type>()`: ๐Ÿšง Returns the result or default value directly as the specified type if possible, can be vector to return all results, and a non-vector to get the result according to the MultiOptionPolicy in place. 462 +- `results(variable_to_bind_to)`: ๐Ÿ†• Gets the results according to the MultiOptionPolicy and converts them just like the `add_option_function` with a variable.
  463 +- `Value=as<type>()`: ๐Ÿ†• Returns the result or default value directly as the specified type if possible, can be vector to return all results, and a non-vector to get the result according to the MultiOptionPolicy in place.
451 464
452 ### Subcommands 465 ### Subcommands
453 466
454 -Subcommands are supported, and can be nested infinitely. To add a subcommand, call the `add_subcommand` method with a name and an optional description. This gives a pointer to an `App` that behaves just like the main app, and can take options or further subcommands. Add `->ignore_case()` to a subcommand to allow any variation of caps to also be accepted. ๐Ÿ†• `->ignore_underscore()` is similar, but for underscores. Children inherit the current setting from the parent. You cannot add multiple matching subcommand names at the same level (including `ignore_case` and ๐Ÿ†• `ignore_underscore`). 467 +Subcommands are supported, and can be nested infinitely. To add a subcommand, call the `add_subcommand` method with a name and an optional description. This gives a pointer to an `App` that behaves just like the main app, and can take options or further subcommands. Add `->ignore_case()` to a subcommand to allow any variation of caps to also be accepted. `->ignore_underscore()` is similar, but for underscores. Children inherit the current setting from the parent. You cannot add multiple matching subcommand names at the same level (including `ignore_case` and `ignore_underscore`).
455 468
456 If you want to require that at least one subcommand is given, use `.require_subcommand()` on the parent app. You can optionally give an exact number of subcommands to require, as well. If you give two arguments, that sets the min and max number allowed. 469 If you want to require that at least one subcommand is given, use `.require_subcommand()` on the parent app. You can optionally give an exact number of subcommands to require, as well. If you give two arguments, that sets the min and max number allowed.
457 0 for the max number allowed will allow an unlimited number of subcommands. As a handy shortcut, a single negative value N will set "up to N" values. Limiting the maximum number allows you to keep arguments that match a previous 470 0 for the max number allowed will allow an unlimited number of subcommands. As a handy shortcut, a single negative value N will set "up to N" values. Limiting the maximum number allows you to keep arguments that match a previous
@@ -463,9 +476,9 @@ All `App`s have a `get_subcommands()` method, which returns a list of pointers t @@ -463,9 +476,9 @@ All `App`s have a `get_subcommands()` method, which returns a list of pointers t
463 For many cases, however, using an app's callback may be easier. Every app executes a callback function after it parses; just use a lambda function (with capture to get parsed values) to `.callback`. If you throw `CLI::Success` or `CLI::RuntimeError(return_value)`, you can 476 For many cases, however, using an app's callback may be easier. Every app executes a callback function after it parses; just use a lambda function (with capture to get parsed values) to `.callback`. If you throw `CLI::Success` or `CLI::RuntimeError(return_value)`, you can
464 even exit the program through the callback. The main `App` has a callback slot, as well, but it is generally not as useful. 477 even exit the program through the callback. The main `App` has a callback slot, as well, but it is generally not as useful.
465 You are allowed to throw `CLI::Success` in the callbacks. 478 You are allowed to throw `CLI::Success` in the callbacks.
466 -Multiple subcommands are allowed, to allow [`Click`][click] like series of commands (order is preserved). The same subcommand can be triggered multiple times but all positional arguments will take precedence over the second and future calls of the subcommand. `->count()` on the subcommand will return the number of times the subcommand was called. The subcommand callback will only be triggered once unless the `.immediate_callback()` flag is set. In which case the callback executes on completion of the subcommand arguments but after the arguments for that subcommand have been parsed, and can be triggered multiple times. 479 +Multiple subcommands are allowed, to allow [`Click`][click] like series of commands (order is preserved). ๐Ÿ†• The same subcommand can be triggered multiple times but all positional arguments will take precedence over the second and future calls of the subcommand. `->count()` on the subcommand will return the number of times the subcommand was called. The subcommand callback will only be triggered once unless the `.immediate_callback()` ๐Ÿ†• flag is set. In which case the callback executes on completion of the subcommand arguments but after the arguments for that subcommand have been parsed, and can be triggered multiple times.
467 480
468 -๐Ÿšง Subcommands may also have an empty name either by calling `add_subcommand` with an empty string for the name or with no arguments. 481 +๐Ÿ†• Subcommands may also have an empty name either by calling `add_subcommand` with an empty string for the name or with no arguments.
469 Nameless subcommands function a similarly to groups in the main `App`. See [Option groups](#option-groups) to see how this might work. If an option is not defined in the main App, all nameless subcommands are checked as well. This allows for the options to be defined in a composable group. The `add_subcommand` function has an overload for adding a `shared_ptr<App>` so the subcommand(s) could be defined in different components and merged into a main `App`, or possibly multiple `Apps`. Multiple nameless subcommands are allowed. Callbacks for nameless subcommands are only triggered if any options from the subcommand were parsed. 482 Nameless subcommands function a similarly to groups in the main `App`. See [Option groups](#option-groups) to see how this might work. If an option is not defined in the main App, all nameless subcommands are checked as well. This allows for the options to be defined in a composable group. The `add_subcommand` function has an overload for adding a `shared_ptr<App>` so the subcommand(s) could be defined in different components and merged into a main `App`, or possibly multiple `Apps`. Multiple nameless subcommands are allowed. Callbacks for nameless subcommands are only triggered if any options from the subcommand were parsed.
470 483
471 #### Subcommand options 484 #### Subcommand options
@@ -473,58 +486,58 @@ Nameless subcommands function a similarly to groups in the main `App`. See [Opti @@ -473,58 +486,58 @@ Nameless subcommands function a similarly to groups in the main `App`. See [Opti
473 There are several options that are supported on the main app and subcommands and option_groups. These are: 486 There are several options that are supported on the main app and subcommands and option_groups. These are:
474 487
475 - `.ignore_case()`: Ignore the case of this subcommand. Inherited by added subcommands, so is usually used on the main `App`. 488 - `.ignore_case()`: Ignore the case of this subcommand. Inherited by added subcommands, so is usually used on the main `App`.
476 -- `.ignore_underscore()`: ๐Ÿ†• Ignore any underscores in the subcommand name. Inherited by added subcommands, so is usually used on the main `App`.  
477 -- `.allow_windows_style_options()`: ๐Ÿ†• Allow command line options to be parsed in the form of `/s /long /file:file_name.ext` This option does not change how options are specified in the `add_option` calls or the ability to process options in the form of `-s --long --file=file_name.ext`. 489 +- `.ignore_underscore()`: Ignore any underscores in the subcommand name. Inherited by added subcommands, so is usually used on the main `App`.
  490 +- `.allow_windows_style_options()`: Allow command line options to be parsed in the form of `/s /long /file:file_name.ext` This option does not change how options are specified in the `add_option` calls or the ability to process options in the form of `-s --long --file=file_name.ext`.
478 - `.fallthrough()`: Allow extra unmatched options and positionals to "fall through" and be matched on a parent command. Subcommands always are allowed to fall through. 491 - `.fallthrough()`: Allow extra unmatched options and positionals to "fall through" and be matched on a parent command. Subcommands always are allowed to fall through.
479 -- `.disable()`: ๐Ÿšง Specify that the subcommand is disabled, if given with a bool value it will enable or disable the subcommand or option group.  
480 -- `.disabled_by_default()`: ๐Ÿšง Specify that at the start of parsing the subcommand/option_group should be disabled. This is useful for allowing some Subcommands to trigger others.  
481 -- `.enabled_by_default()`: ๐Ÿšง Specify that at the start of each parse the subcommand/option_group should be enabled. This is useful for allowing some Subcommands to disable others.  
482 -- `.validate_positionals()`: ๐Ÿšง Specify that positionals should pass validation before matching. Validation is specified through `transform`, `check`, and `each` for an option. If an argument fails validation it is not an error and matching proceeds to the next available positional or extra arguments.  
483 -- `.excludes(option_or_subcommand)`: ๐Ÿšง If given an option pointer or pointer to another subcommand, these subcommands cannot be given together. In the case of options, if the option is passed the subcommand cannot be used and will generate an error.  
484 -- `.require_option()`: ๐Ÿšง Require 1 or more options or option groups be used.  
485 -- `.require_option(N)`: ๐Ÿšง Require `N` options or option groups, if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default to 0 or more.  
486 -- `.require_option(min, max)`: ๐Ÿšง Explicitly set min and max allowed options or option groups. Setting `max` to 0 implies unlimited options. 492 +- `.disable()`: ๐Ÿ†• Specify that the subcommand is disabled, if given with a bool value it will enable or disable the subcommand or option group.
  493 +- `.disabled_by_default()`: ๐Ÿ†• Specify that at the start of parsing the subcommand/option_group should be disabled. This is useful for allowing some Subcommands to trigger others.
  494 +- `.enabled_by_default()`: ๐Ÿ†• Specify that at the start of each parse the subcommand/option_group should be enabled. This is useful for allowing some Subcommands to disable others.
  495 +- `.validate_positionals()`: ๐Ÿ†• Specify that positionals should pass validation before matching. Validation is specified through `transform`, `check`, and `each` for an option. If an argument fails validation it is not an error and matching proceeds to the next available positional or extra arguments.
  496 +- `.excludes(option_or_subcommand)`: ๐Ÿ†• If given an option pointer or pointer to another subcommand, these subcommands cannot be given together. In the case of options, if the option is passed the subcommand cannot be used and will generate an error.
  497 +- `.require_option()`: ๐Ÿ†• Require 1 or more options or option groups be used.
  498 +- `.require_option(N)`: ๐Ÿ†• Require `N` options or option groups, if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default to 0 or more.
  499 +- `.require_option(min, max)`: ๐Ÿ†• Explicitly set min and max allowed options or option groups. Setting `max` to 0 implies unlimited options.
487 - `.require_subcommand()`: Require 1 or more subcommands. 500 - `.require_subcommand()`: Require 1 or more subcommands.
488 - `.require_subcommand(N)`: Require `N` subcommands if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default to 0 or more. 501 - `.require_subcommand(N)`: Require `N` subcommands if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default to 0 or more.
489 - `.require_subcommand(min, max)`: Explicitly set min and max allowed subcommands. Setting `max` to 0 is unlimited. 502 - `.require_subcommand(min, max)`: Explicitly set min and max allowed subcommands. Setting `max` to 0 is unlimited.
490 - `.add_subcommand(name="", description="")`: Add a subcommand, returns a pointer to the internally stored subcommand. 503 - `.add_subcommand(name="", description="")`: Add a subcommand, returns a pointer to the internally stored subcommand.
491 -- `.add_subcommand(shared_ptr<App>)`: ๐Ÿšง Add a subcommand by shared_ptr, returns a pointer to the internally stored subcommand.  
492 -- `.remove_subcommand(App)`: ๐Ÿšง Remove a subcommand from the app or subcommand. 504 +- `.add_subcommand(shared_ptr<App>)`: ๐Ÿ†• Add a subcommand by shared_ptr, returns a pointer to the internally stored subcommand.
  505 +- `.remove_subcommand(App)`: ๐Ÿ†• Remove a subcommand from the app or subcommand.
493 - `.got_subcommand(App_or_name)`: Check to see if a subcommand was received on the command line. 506 - `.got_subcommand(App_or_name)`: Check to see if a subcommand was received on the command line.
494 - `.get_subcommands(filter)`: The list of subcommands that match a particular filter function. 507 - `.get_subcommands(filter)`: The list of subcommands that match a particular filter function.
495 -- `.add_option_group(name="", description="")`: ๐Ÿšง Add an [option group](#option-groups) to an App, an option group is specialized subcommand intended for containing groups of options or other groups for controlling how options interact. 508 +- `.add_option_group(name="", description="")`: ๐Ÿ†• Add an [option group](#option-groups) to an App, an option group is specialized subcommand intended for containing groups of options or other groups for controlling how options interact.
496 - `.get_parent()`: Get the parent App or `nullptr` if called on master App. 509 - `.get_parent()`: Get the parent App or `nullptr` if called on master App.
497 - `.get_option(name)`: Get an option pointer by option name will throw if the specified option is not available, nameless subcommands are also searched 510 - `.get_option(name)`: Get an option pointer by option name will throw if the specified option is not available, nameless subcommands are also searched
498 -- `.get_option_no_throw(name)`: ๐Ÿšง Get an option pointer by option name. This function will return a `nullptr` instead of throwing if the option is not available. 511 +- `.get_option_no_throw(name)`: ๐Ÿ†• Get an option pointer by option name. This function will return a `nullptr` instead of throwing if the option is not available.
499 - `.get_options(filter)`: Get the list of all defined option pointers (useful for processing the app for custom output formats). 512 - `.get_options(filter)`: Get the list of all defined option pointers (useful for processing the app for custom output formats).
500 - `.parse_order()`: Get the list of option pointers in the order they were parsed (including duplicates). 513 - `.parse_order()`: Get the list of option pointers in the order they were parsed (including duplicates).
501 - `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details. 514 - `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details.
502 -- `.description(str)`: ๐Ÿ†• Set/change the description. 515 +- `.description(str)`: Set/change the description.
503 - `.get_description()`: Access the description. 516 - `.get_description()`: Access the description.
504 - `.parsed()`: True if this subcommand was given on the command line. 517 - `.parsed()`: True if this subcommand was given on the command line.
505 - `.count()`: Returns the number of times the subcommand was called. 518 - `.count()`: Returns the number of times the subcommand was called.
506 - `.count(option_name)`: Returns the number of times a particular option was called. 519 - `.count(option_name)`: Returns the number of times a particular option was called.
507 -- `.count_all()`: ๐Ÿšง Returns the total number of arguments a particular subcommand processed, on the master App it returns the total number of processed commands. 520 +- `.count_all()`: ๐Ÿ†• Returns the total number of arguments a particular subcommand processed, on the master App it returns the total number of processed commands.
508 - `.name(name)`: Add or change the name. 521 - `.name(name)`: Add or change the name.
509 - `.callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. See [Subcommand callbacks](#callbacks) for some additional details. 522 - `.callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. See [Subcommand callbacks](#callbacks) for some additional details.
510 -- `.immediate_callback()`: ๐Ÿšง Specify that the callback for a subcommand should run immediately on completion of a subcommand vs at the completion of all parsing if this option is not used.  
511 -- `.pre_parse_callback(void(size_t) function)`: ๐Ÿšง Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details. 523 +- `.immediate_callback()`: ๐Ÿ†• Specify that the callback for a subcommand should run immediately on completion of a subcommand vs at the completion of all parsing if this option is not used.
  524 +- `.pre_parse_callback(void(size_t) function)`: ๐Ÿ†• Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details.
512 - `.allow_extras()`: Do not throw an error if extra arguments are left over. 525 - `.allow_extras()`: Do not throw an error if extra arguments are left over.
513 -- `.positionals_at_end()`: ๐Ÿšง Specify that positional arguments occur as the last arguments and throw an error if an unexpected positional is encountered. 526 +- `.positionals_at_end()`: ๐Ÿ†• Specify that positional arguments occur as the last arguments and throw an error if an unexpected positional is encountered.
514 - `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognized item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app. 527 - `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognized item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app.
515 - `.footer(message)`: Set text to appear at the bottom of the help string. 528 - `.footer(message)`: Set text to appear at the bottom of the help string.
516 - `.set_help_flag(name, message)`: Set the help flag name and message, returns a pointer to the created option. 529 - `.set_help_flag(name, message)`: Set the help flag name and message, returns a pointer to the created option.
517 - `.set_help_all_flag(name, message)`: Set the help all flag name and message, returns a pointer to the created option. Expands subcommands. 530 - `.set_help_all_flag(name, message)`: Set the help all flag name and message, returns a pointer to the created option. Expands subcommands.
518 - `.failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default). 531 - `.failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default).
519 - `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand. 532 - `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand.
520 -- `[option_name]`: ๐Ÿšง retrieve a const pointer to an option given by `option_name` for Example `app["--flag1"]` will get a pointer to the option for the "--flag1" value, `app["--flag1"]->as<bool>()` will get the results of the command line for a flag. 533 +- `[option_name]`: ๐Ÿ†• retrieve a const pointer to an option given by `option_name` for Example `app["--flag1"]` will get a pointer to the option for the "--flag1" value, `app["--flag1"]->as<bool>()` will get the results of the command line for a flag. The operation will throw an exception if the option name is not valid.
521 534
522 > Note: if you have a fixed number of required positional options, that will match before subcommand names. `{}` is an empty filter function, and any positional argument will match before repeated subcommand names. 535 > Note: if you have a fixed number of required positional options, that will match before subcommand names. `{}` is an empty filter function, and any positional argument will match before repeated subcommand names.
523 536
524 537
525 #### Callbacks 538 #### Callbacks
526 -A subcommand has two optional callbacks that are executed at different stages of processing. The `preparse_callback` ๐Ÿšง is executed once after the first argument of a subcommand or application is processed and gives an argument for the number of remaining arguments to process. For the main app the first argument is considered the program name, for subcommands the first argument is the subcommand name. For Option groups and nameless subcommands the first argument is after the first argument or subcommand is processed from that group.  
527 -The second callback is executed after parsing. The behavior depends on the status of the `immediate_callback` flag ๐Ÿšง. If true, this runs immediately after the parsing of the subcommand. Or if the flag is false, once after parsing of all arguments. If the `immediate_callback` is set then the callback can be executed multiple times if the subcommand list given multiple times. If the main app or subcommand has a config file, no data from the config file will be reflected in immediate_callback. `immediate_callback()` has no effect on the main app, though it can be inherited. For option_groups `immediate_callback` causes the callback to be run prior to other option groups and options in the main app, effectively giving the options in the group priority. 539 +A subcommand has two optional callbacks that are executed at different stages of processing. The `preparse_callback` ๐Ÿ†• is executed once after the first argument of a subcommand or application is processed and gives an argument for the number of remaining arguments to process. For the main app the first argument is considered the program name, for subcommands the first argument is the subcommand name. For Option groups and nameless subcommands the first argument is after the first argument or subcommand is processed from that group.
  540 +The second callback is executed after parsing. The behavior depends on the status of the `immediate_callback` flag ๐Ÿ†•. If true, this runs immediately after the parsing of the subcommand. Or if the flag is false, once after parsing of all arguments. If the `immediate_callback` is set then the callback can be executed multiple times if the subcommand list given multiple times. If the main app or subcommand has a config file, no data from the config file will be reflected in immediate_callback. `immediate_callback()` has no effect on the main app, though it can be inherited. For option_groups `immediate_callback` causes the callback to be run prior to other option groups and options in the main app, effectively giving the options in the group priority.
528 541
529 For example say an application was set up like 542 For example say an application was set up like
530 543
@@ -562,7 +575,7 @@ If the `immediate_callback` flag is set then all contained options are processed @@ -562,7 +575,7 @@ If the `immediate_callback` flag is set then all contained options are processed
562 575
563 576
564 577
565 -#### Option groups ๐Ÿšง 578 +#### Option groups ๐Ÿ†•
566 579
567 The subcommand method 580 The subcommand method
568 581
@@ -589,7 +602,7 @@ This results in the subcommand being moved from its parent into the option group @@ -589,7 +602,7 @@ This results in the subcommand being moved from its parent into the option group
589 Options in an option group are searched for a command line match after any options in the main app, so any positionals in the main app would be matched first. So care must be taken to make sure of the order when using positional arguments and option groups. 602 Options in an option group are searched for a command line match after any options in the main app, so any positionals in the main app would be matched first. So care must be taken to make sure of the order when using positional arguments and option groups.
590 Option groups work well with `excludes` and `require_options` methods, as an application will treat an option group as a single option for the purpose of counting and requirements, and an option group will be considered used if any of the options or subcommands contained in it are used. Option groups allow specifying requirements such as requiring 1 of 3 options in one group and 1 of 3 options in a different group. Option groups can contain other groups as well. Disabling an option group will turn off all options within the group. 603 Option groups work well with `excludes` and `require_options` methods, as an application will treat an option group as a single option for the purpose of counting and requirements, and an option group will be considered used if any of the options or subcommands contained in it are used. Option groups allow specifying requirements such as requiring 1 of 3 options in one group and 1 of 3 options in a different group. Option groups can contain other groups as well. Disabling an option group will turn off all options within the group.
591 604
592 -The `CLI::TriggerOn` ๐Ÿšง and `CLI::TriggerOff` ๐Ÿšง methods are helper methods to allow the use of options/subcommands from one group to trigger another group on or off. 605 +The `CLI::TriggerOn` ๐Ÿ†• and `CLI::TriggerOff` ๐Ÿ†• methods are helper methods to allow the use of options/subcommands from one group to trigger another group on or off.
593 606
594 ```cpp 607 ```cpp
595 CLI::TriggerOn(group1_pointer, triggered_group); 608 CLI::TriggerOn(group1_pointer, triggered_group);
@@ -625,16 +638,16 @@ in_subcommand = Wow @@ -625,16 +638,16 @@ in_subcommand = Wow
625 sub.subcommand = true 638 sub.subcommand = true
626 ``` 639 ```
627 640
628 -Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `yes`, ๐Ÿšง `enable`; or `false`, `off`, `0`, `no`, ๐Ÿšง `disable` (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not mean that subcommand was passed, it just sets the "defaults". You cannot set positional-only arguments or force subcommands to be present in the command line. 641 +Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `yes`, ๐Ÿ†• `enable`; or `false`, `off`, `0`, `no`, ๐Ÿ†• `disable` (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not mean that subcommand was passed, it just sets the "defaults". You cannot set positional-only arguments or force subcommands to be present in the command line.
629 642
630 To print a configuration file from the passed 643 To print a configuration file from the passed
631 arguments, use `.config_to_str(default_also=false, prefix="", write_description=false)`, where `default_also` will also show any defaulted arguments, `prefix` will add a prefix, and `write_description` will include option descriptions. 644 arguments, use `.config_to_str(default_also=false, prefix="", write_description=false)`, where `default_also` will also show any defaulted arguments, `prefix` will add a prefix, and `write_description` will include option descriptions.
632 645
633 ### Inheriting defaults 646 ### Inheriting defaults
634 647
635 -Many of the defaults for subcommands and even options are inherited from their creators. The inherited default values for subcommands are `allow_extras`, `prefix_command`, `ignore_case`, ๐Ÿ†• `ignore_underscore`, `fallthrough`, `group`, `footer`,`immediate_callback` and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well. 648 +Many of the defaults for subcommands and even options are inherited from their creators. The inherited default values for subcommands are `allow_extras`, `prefix_command`, `ignore_case`, `ignore_underscore`, `fallthrough`, `group`, `footer`,`immediate_callback` and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well.
636 649
637 -Options have defaults for `group`, `required`, `multi_option_policy`, `ignore_case`, ๐Ÿ†• `ignore_underscore`, ๐Ÿšง `delimiter`, and ๐Ÿšง `disable_flag_override`. To set these defaults, you should set the `option_defaults()` object, for example: 650 +Options have defaults for `group`, `required`, `multi_option_policy`, `ignore_case`, `ignore_underscore`, ๐Ÿ†• `delimiter`, and ๐Ÿ†• `disable_flag_override`. To set these defaults, you should set the `option_defaults()` object, for example:
638 651
639 ```cpp 652 ```cpp
640 app.option_defaults()->required(); 653 app.option_defaults()->required();
@@ -658,10 +671,10 @@ The App class was designed allow toolkits to subclass it, to provide preset defa @@ -658,10 +671,10 @@ The App class was designed allow toolkits to subclass it, to provide preset defa
658 but before run behavior, while 671 but before run behavior, while
659 still giving the user freedom to `callback` on the main app. 672 still giving the user freedom to `callback` on the main app.
660 673
661 -The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector. ๐Ÿ†• You can also use `parse(string, bool)` to split up and parse a string; the optional bool should be set to true if you are 674 +The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector. You can also use `parse(string, bool)` to split up and parse a string; the optional bool should be set to true if you are
662 including the program name in the string, and false otherwise. 675 including the program name in the string, and false otherwise.
663 676
664 -Also, in a related note, the `App` you get a pointer to is stored in the parent `App` in a `unique_ptr`s (like `Option`s) and are deleted when the main `App` goes out of scope. 677 +Also, in a related note, the `App` you get a pointer to is stored in the parent `App` in a `shared_ptr`s (similar to `Option`s) and are deleted when the main `App` goes out of scope unless the object has another owner.
665 678
666 ### How it works 679 ### How it works
667 680
include/CLI/Version.hpp
@@ -6,8 +6,8 @@ @@ -6,8 +6,8 @@
6 // [CLI11:verbatim] 6 // [CLI11:verbatim]
7 7
8 #define CLI11_VERSION_MAJOR 1 8 #define CLI11_VERSION_MAJOR 1
9 -#define CLI11_VERSION_MINOR 7  
10 -#define CLI11_VERSION_PATCH 1  
11 -#define CLI11_VERSION "1.7.1" 9 +#define CLI11_VERSION_MINOR 8
  10 +#define CLI11_VERSION_PATCH 0
  11 +#define CLI11_VERSION "1.8.0"
12 12
13 // [CLI11:verbatim] 13 // [CLI11:verbatim]