Commit 33be37ae4ce61fd4635ca456524bb6ae55bd9f7e

Authored by Henry Fredrick Schreiner
1 parent c4fe25b6

Add new symbols to 1.7 features

[skip ci]
Showing 1 changed file with 17 additions and 19 deletions
README.md
... ... @@ -213,13 +213,13 @@ App* subcom = app.add_subcommand(name, description);
213 213 - set_of_possible_options, // Set will be copied, ignores changes
214 214 - help_string="",
215 215 - default=false)
216   --app.add_mutable_set(... // Set can change later, keeps reference
  216 +-app.add_mutable_set(... // ๐Ÿ†• Set can change later, keeps reference
217 217 -app.add_set_ignore_case(... // String only
218   --app.add_mutable_set_ignore_case(... // String only
219   --app.add_set_ignore_underscore(... // String only
220   --app.add_mutable_set_ignore_underscore(... // String only
221   --app.add_set_ignore_case_underscore(... // String only
222   --app.add_mutable_set_ignore_case_underscore(... // String only
  218 +-app.add_mutable_set_ignore_case(... // ๐Ÿ†• String only
  219 +-app.add_set_ignore_underscore(... // ๐Ÿ†• String only
  220 +-app.add_mutable_set_ignore_underscore(... // ๐Ÿ†• String only
  221 +-app.add_set_ignore_case_underscore(... // ๐Ÿ†• String only
  222 +-app.add_mutable_set_ignore_case_underscore(... // ๐Ÿ†• String only
223 223 ```
224 224  
225 225 An option name must start with a alphabetic character, underscore, or a number. For long options, anything but an equals sign or a comma is valid after that, though 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 help line for its positional form. If you want the default value to print in the help description, pass in `true` for the final parameter for `add_option`.
... ... @@ -273,7 +273,7 @@ Before parsing, you can set the following options:
273 273 - `->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
274 274 - `->disable_flag_override()`: ๐Ÿšง from the command line long form flag option 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.
275 275 - `->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
276   -- `->description(str)`: Set/change the description.
  276 +- `->description(str)`: ๐Ÿ†• Set/change the description.
277 277 - `->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).
278 278 - `->check(CLI::IsMember(...))`: ๐Ÿšง Require an option be a member of a given set. See below for options.
279 279 - `->transform(CLI::IsMember(...))`: ๐Ÿšง Require an option be a member of a given set or map. Can change the parse. See below for options.
... ... @@ -291,9 +291,7 @@ Before parsing, you can set the following options:
291 291  
292 292 These options return the `Option` pointer, so you can chain them together, and even skip storing the pointer entirely. Check 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 `check` and `transform` use the same underlying mechanism, you can chain as many as you want, and they will be executed in order. If you just want to see the unconverted values, use `.results()` to get the `std::vector<std::string>` of results. Validate can also be a subclass of `CLI::Validator`, in which case it can also set the type name and can be combined with `&` and `|` (all built-in validators are this sort). Validators can also be inverted with `!` such as `->check(!CLI::ExistingFile)` which would check that a file doesn't exist.
293 293  
294   -> ๐Ÿšง IsMember is new in CLI11 1.8
295   -
296   -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 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.
  294 +๐Ÿšง 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 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.
297 295 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`.
298 296 Here are some examples
299 297 of `IsMember`:
... ... @@ -317,7 +315,7 @@ On the command line, options can be given as:
317 315 - `--file filename` (space)
318 316 - `--file=filename` (equals)
319 317  
320   -If `allow_windows_style_options()` is specified in the application or subcommand options can also be given as:
  318 +๐Ÿ†• If `allow_windows_style_options()` is specified in the application or subcommand options can also be given as:
321 319 - `/a` (flag)
322 320 - `/f filename` (option)
323 321 - `/long` (long flag)
... ... @@ -344,7 +342,7 @@ In most cases the fastest and easiest way is to return the results through a cal
344 342  
345 343 ### Subcommands
346 344  
347   -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`).
  345 +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`).
348 346  
349 347 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.
350 348 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
... ... @@ -366,8 +364,8 @@ Nameless subcommands function a similarly to groups in the main `App`. If an op
366 364 There are several options that are supported on the main app and subcommands. These are:
367 365  
368 366 - `.ignore_case()`: Ignore the case of this subcommand. Inherited by added subcommands, so is usually used on the main `App`.
369   -- `.ignore_underscore()`: Ignore any underscores in the subcommand name. Inherited by added subcommands, so is usually used on the main `App`.
370   -- `.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`
  367 +- `.ignore_underscore()`: ๐Ÿ†• Ignore any underscores in the subcommand name. Inherited by added subcommands, so is usually used on the main `App`.
  368 +- `.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`
371 369 - `.fallthrough()`: Allow extra unmatched options and positionals to "fall through" and be matched on a parent command. Subcommands always are allowed to fall through.
372 370 - `.require_subcommand()`: Require 1 or more subcommands.
373 371 - `.require_subcommand(N)`: Require `N` subcommands if `N>0`, or up to `N` if `N<0`. `N=0` resets to the default 0 or more.
... ... @@ -382,7 +380,7 @@ There are several options that are supported on the main app and subcommands. Th
382 380 - `.get_options(filter)`: Get the list of all defined option pointers (useful for processing the app for custom output formats).
383 381 - `.parse_order()`: Get the list of option pointers in the order they were parsed (including duplicates).
384 382 - `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details.
385   -- `.description(str)`: Set/change the description.
  383 +- `.description(str)`: ๐Ÿ†• Set/change the description.
386 384 - `.get_description()`: Access the description.
387 385 - `.parsed()`: True if this subcommand was given on the command line.
388 386 - `.name(name)`: Add or change the name.
... ... @@ -425,16 +423,16 @@ in_subcommand = Wow
425 423 sub.subcommand = true
426 424 ```
427 425  
428   -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.
  426 +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.
429 427  
430 428 To print a configuration file from the passed
431 429 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.
432 430  
433 431 ### Inheriting defaults
434 432  
435   -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`, and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well.
  433 +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`, and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well.
436 434  
437   -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:
  435 +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:
438 436  
439 437 ```cpp
440 438 app.option_defaults()->required();
... ... @@ -458,7 +456,7 @@ The App class was designed allow toolkits to subclass it, to provide preset defa
458 456 but before run behavior, while
459 457 still giving the user freedom to `callback` on the main app.
460 458  
461   -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
  459 +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
462 460 including the program name in the string, and false otherwise.
463 461  
464 462 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.
... ...