Commit 469813121633c5f07807434409452c85a9b12f55

Authored by Henry Schreiner
Committed by Henry Schreiner
1 parent f27f6f20

style: add mdlint

.github/CONTRIBUTING.md
  1 +# Contributing
  2 +
1 3 Thanks for considering to write a Pull Request (PR) for CLI11! Here are a few guidelines to get you started:
2 4  
3 5 Make sure you are comfortable with the license; all contributions are licensed under the original license.
4 6  
5 7 ## Adding functionality
  8 +
6 9 Make sure any new functions you add are are:
7 10  
8 11 * Documented by `///` documentation for Doxygen
... ... @@ -20,10 +23,9 @@ In general, make sure the addition is well thought out and does not increase the
20 23 * Everything must pass clang-tidy as well, run with `-DCLI11_CLANG_TIDY=ON` (if you set `-DCLI11_CLANG_TIDY_OPTIONS="-fix"`, make sure you use a single threaded build process, or just build one example target).
21 24 * Your changes must also conform to most of the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) rules checked by [cpplint](https://github.com/cpplint/cpplint). For unused cpplint filters and justifications, see [CPPLINT.cfg](/CPPLINT.cfg).
22 25  
23   -
24 26 ## Pre-commit
25 27  
26   -Format is handled by pre-commit. You should install it:
  28 +Format is handled by pre-commit. You should install it (or use [pipx](https://pypa.github.io/pipx/)):
27 29  
28 30 ```bash
29 31 python3 -m pip install pre-commit
... ... @@ -37,7 +39,6 @@ pre-commit run
37 39 pre-commit run --all-files
38 40 ```
39 41  
40   -
41 42 And, if you want to always use it, you can install it as a git hook (hence the name, pre-commit):
42 43  
43 44 ```bash
... ... @@ -72,6 +73,7 @@ yarn all-contributors add username code,bug
72 73 Remember to replace the emoji in the readme, being careful not to replace the ones in all-contributors if any overlap.
73 74  
74 75 Steps:
  76 +
75 77 * Update changelog if needed
76 78 * Update the version in `.appveyor.yml` and `include/CLI/Version.hpp`.
77 79 * Find and replace in README:
... ...
.pre-commit-config.yaml
1 1 ci:
2 2 autoupdate_commit_msg: "chore(deps): pre-commit.ci autoupdate"
  3 + autofix_commit_msg: "style: pre-commit.ci fixes"
3 4 skip:
4 5 - docker-clang-format
5 6  
... ... @@ -40,6 +41,12 @@ repos:
40 41 - id: cmake-format
41 42 additional_dependencies: [pyyaml]
42 43  
  44 +- repo: https://github.com/markdownlint/markdownlint
  45 + rev: v0.11.0
  46 + hooks:
  47 + - id: markdownlint
  48 + args: ["--style=scripts/mdlint_style.rb"]
  49 +
43 50 - repo: local
44 51 hooks:
45 52 - id: disallow-caps
... ...
CHANGELOG.md
1   -### Version 2.0.1: Single header fix
2   -
3   -The single header file was missing the include guard. #620
4   -
  1 +# Changelog
5 2  
6 3 ## Version 2.0: Simplification
7 4  
... ... @@ -14,9 +11,9 @@ release contains a lot of backend cleanup, including a complete overhaul of the
14 11 testing system and single file generation system.
15 12  
16 13 * Built-in config format is TOML compliant now [#435][]
17   - * Support multiline TOML [#528][]
18   - * Support for configurable quotes [#599][]
19   - * Support short/positional options in config mode [#443][]
  14 + * Support multiline TOML [#528][]
  15 + * Support for configurable quotes [#599][]
  16 + * Support short/positional options in config mode [#443][]
20 17 * More powerful containers, support for `%%` separator [#423][]
21 18 * Support atomic types [#520][] and complex types natively [#423][]
22 19 * Add a type validator `CLI::TypeValidator<TYPE>` [#526][]
... ... @@ -34,14 +31,13 @@ testing system and single file generation system.
34 31 * Bugfix: fix description of non-configurable subcommands in config [#604][]
35 32 * Build: support pkg-config [#523][]
36 33  
37   -#### Converting from CLI11 1.9:
38   -
39   -* Removed deprecated set commands, use validators instead. [#565][]
40   -* The final "defaulted" bool has been removed, use `->capture_default_str()`
41   - instead. Use `app.option_defaults()->always_capture_default()` to set this for
42   - all future options. [#597][]
43   -* Use `add_option` on a complex number instead of `add_complex`, which has been removed.
44   -
  34 +> ### Converting from CLI11 1.9
  35 +>
  36 +> * Removed deprecated set commands, use validators instead. [#565][]
  37 +> * The final "defaulted" bool has been removed, use `->capture_default_str()`
  38 +> instead. Use `app.option_defaults()->always_capture_default()` to set this for
  39 +> all future options. [#597][]
  40 +> * Use `add_option` on a complex number instead of `add_complex`, which has been removed.
45 41  
46 42 [#423]: https://github.com/CLIUtils/CLI11/pull/423
47 43 [#435]: https://github.com/CLIUtils/CLI11/pull/435
... ... @@ -67,27 +63,11 @@ testing system and single file generation system.
67 63 [#605]: https://github.com/CLIUtils/CLI11/pull/605
68 64 [#606]: https://github.com/CLIUtils/CLI11/pull/606
69 65  
  66 +### Version 2.0.1: Single header fix
70 67  
71   -### Version 1.9.1: Backporting fixes
72   -
73   -This is a patch version that backports fixes from the development of 2.0.
74   -
75   -* Support relative inclusion [#475][]
76   -* Fix cases where spaces in paths could break CMake support [#471][]
77   -* Fix an issue with string conversion [#421][]
78   -* Cross-compiling improvement for Conan.io [#430][]
79   -* Fix option group default propagation [#450][]
80   -* Fix for C++20 [#459][]
81   -* Support compiling with RTTI off [#461][]
82   -
83   -[#421]: https://github.com/CLIUtils/CLI11/pull/421
84   -[#430]: https://github.com/CLIUtils/CLI11/pull/430
85   -[#450]: https://github.com/CLIUtils/CLI11/pull/450
86   -[#459]: https://github.com/CLIUtils/CLI11/pull/459
87   -[#461]: https://github.com/CLIUtils/CLI11/pull/461
88   -[#471]: https://github.com/CLIUtils/CLI11/pull/471
89   -[#475]: https://github.com/CLIUtils/CLI11/pull/475
  68 +The single header file was missing the include guard. [#620][]
90 69  
  70 +[#620]: https://github.com/CLIUtils/CLI11/pull/620
91 71  
92 72 ## Version 1.9: Config files and cleanup
93 73  
... ... @@ -127,11 +107,11 @@ configuration options were added to facilitate a wider variety of apps. GCC
127 107 * Build: GCC 4.7 is no longer supported, due mostly to GoogleTest. GCC 4.8+ is now required. [#160][]
128 108 * Build: Restructured significant portions of CMake build system [#394][]
129 109  
130   -> ### Converting from CLI11 1.8:
  110 +> ### Converting from CLI11 1.8
131 111 >
132 112 > * Some deprecated methods dropped
133   -> - `add_set*` should be replaced with `->check`/`->transform` and `CLI::IsMember` since 1.8
134   -> - `get_defaultval` was replaced by `get_default_str` in 1.8
  113 +> * `add_set*` should be replaced with `->check`/`->transform` and `CLI::IsMember` since 1.8
  114 +> * `get_defaultval` was replaced by `get_default_str` in 1.8
135 115 > * The true/false 4th argument to `add_option` is expected to be removed in 2.0, use `->capture_default_str()` since 1.8
136 116  
137 117 [#160]: https://github.com/CLIUtils/CLI11/pull/160
... ... @@ -147,7 +127,6 @@ configuration options were added to facilitate a wider variety of apps. GCC
147 127 [#307]: https://github.com/CLIUtils/CLI11/pull/307
148 128 [#309]: https://github.com/CLIUtils/CLI11/pull/309
149 129 [#310]: https://github.com/CLIUtils/CLI11/pull/310
150   -[#312]: https://github.com/CLIUtils/CLI11/pull/312
151 130 [#313]: https://github.com/CLIUtils/CLI11/pull/313
152 131 [#317]: https://github.com/CLIUtils/CLI11/pull/317
153 132 [#318]: https://github.com/CLIUtils/CLI11/pull/318
... ... @@ -155,6 +134,7 @@ configuration options were added to facilitate a wider variety of apps. GCC
155 134 [#325]: https://github.com/CLIUtils/CLI11/pull/325
156 135 [#333]: https://github.com/CLIUtils/CLI11/pull/333
157 136 [#336]: https://github.com/CLIUtils/CLI11/pull/336
  137 +[#341]: https://github.com/CLIUtils/CLI11/pull/341
158 138 [#342]: https://github.com/CLIUtils/CLI11/pull/342
159 139 [#348]: https://github.com/CLIUtils/CLI11/pull/348
160 140 [#349]: https://github.com/CLIUtils/CLI11/pull/349
... ... @@ -173,6 +153,25 @@ configuration options were added to facilitate a wider variety of apps. GCC
173 153 [#394]: https://github.com/CLIUtils/CLI11/pull/394
174 154 [#400]: https://github.com/CLIUtils/CLI11/pull/400
175 155  
  156 +### Version 1.9.1: Backporting fixes
  157 +
  158 +This is a patch version that backports fixes from the development of 2.0.
  159 +
  160 +* Support relative inclusion [#475][]
  161 +* Fix cases where spaces in paths could break CMake support [#471][]
  162 +* Fix an issue with string conversion [#421][]
  163 +* Cross-compiling improvement for Conan.io [#430][]
  164 +* Fix option group default propagation [#450][]
  165 +* Fix for C++20 [#459][]
  166 +* Support compiling with RTTI off [#461][]
  167 +
  168 +[#421]: https://github.com/CLIUtils/CLI11/pull/421
  169 +[#430]: https://github.com/CLIUtils/CLI11/pull/430
  170 +[#450]: https://github.com/CLIUtils/CLI11/pull/450
  171 +[#459]: https://github.com/CLIUtils/CLI11/pull/459
  172 +[#461]: https://github.com/CLIUtils/CLI11/pull/461
  173 +[#471]: https://github.com/CLIUtils/CLI11/pull/471
  174 +[#475]: https://github.com/CLIUtils/CLI11/pull/475
176 175  
177 176 ## Version 1.8: Transformers, default strings, and flags
178 177  
... ... @@ -201,7 +200,7 @@ Set handling has been completely replaced by a new backend that works as a Valid
201 200 * Respect `BUILD_TESTING` only if CLI11 is the main project; otherwise, `CLI11_TESTING` must be used [#277][]
202 201 * Drop auto-detection of experimental optional and boost::optional; must be enabled explicitly (too fragile) [#277][] [#279][]
203 202  
204   -> ### Converting from CLI11 1.7:
  203 +> ### Converting from CLI11 1.7
205 204 >
206 205 > * `.add_option(..., true)` should be replaced by `.add_option(...)->capture_default_str()` or `app.option_defaults()->always_capture_default()` can be used
207 206 > * `app.add_set("--name", value, {"choice1", "choice2"})` should become `app.add_option("--name", value)->check(CLI::IsMember({"choice1", "choice2"}))`
... ... @@ -237,20 +236,6 @@ Set handling has been completely replaced by a new backend that works as a Valid
237 236 [#277]: https://github.com/CLIUtils/CLI11/pull/277
238 237 [#279]: https://github.com/CLIUtils/CLI11/pull/279
239 238  
240   -
241   -## Version 1.7.1: Quick patch
242   -
243   -This version provides a quick patch for a (correct) warning from GCC 8 for the windows options code.
244   -
245   -
246   -* Fix for Windows style option parsing [#201][]
247   -* Improve `add_subcommand` when throwing an exception [#204][]
248   -* Better metadata for Conan package [#202][]
249   -
250   -[#201]: https://github.com/CLIUtils/CLI11/pull/201
251   -[#202]: https://github.com/CLIUtils/CLI11/pull/202
252   -[#204]: https://github.com/CLIUtils/CLI11/pull/204
253   -
254 239 ## Version 1.7: Parse breakup
255 240  
256 241 The parsing procedure now maps much more sensibly to complex, nested subcommand structures. Each phase of the parsing happens on all subcommands before moving on with the next phase of the parse. This allows several features, like required environment variables, to work properly even through subcommand boundaries.
... ... @@ -271,7 +256,7 @@ Passing the same subcommand multiple times is better supported. Several new feat
271 256 * Cleanup warnings [#191][]
272 257 * Remove deprecated names: `set_footer`, `set_name`, `set_callback`, and `set_type_name`. Use without the `set_` instead. [#192][]
273 258  
274   -> ### Converting from CLI11 1.6:
  259 +> ### Converting from CLI11 1.6
275 260 >
276 261 > * `->short_circuit()` is no longer needed, just remove it if you were using it - raising an exception will happen in the proper place now without it.
277 262 > * `->add_set*` becomes `->add_mutable_set*` if you were using the editable set feature
... ... @@ -290,44 +275,17 @@ Passing the same subcommand multiple times is better supported. Several new feat
290 275 [#199]: https://github.com/CLIUtils/CLI11/pull/199
291 276 [#200]: https://github.com/CLIUtils/CLI11/pull/200
292 277  
293   -## Version 1.6.2: Help-all
  278 +### Version 1.7.1: Quick patch
294 279  
295   -This version fixes some formatting bugs with help-all. It also adds fixes for several warnings, including an experimental optional error on Clang 7. Several smaller fixes.
296   -
297   -* Fixed help-all formatting [#163][]
298   - * Printing help-all on nested command now fixed (App)
299   - * Missing space after help-all restored (Default formatter)
300   - * More detail printed on help all (Default formatter)
301   - * Help-all subcommands get indented with inner blank lines removed (Default formatter)
302   - * `detail::find_and_replace` added to utilities
303   -* Fixed CMake install as subproject with `CLI11_INSTALL` flag. [#156][]
304   -* Fixed warning about local variable hiding class member with MSVC [#157][]
305   -* Fixed compile error with default settings on Clang 7 and libc++ [#158][]
306   -* Fixed special case of `--help` on subcommands (general fix planned for 1.7) [#168][]
307   -* Removing an option with links [#179][]
308   -
309   -[#156]: https://github.com/CLIUtils/CLI11/issues/156
310   -[#157]: https://github.com/CLIUtils/CLI11/issues/157
311   -[#158]: https://github.com/CLIUtils/CLI11/issues/158
312   -[#163]: https://github.com/CLIUtils/CLI11/pull/163
313   -[#168]: https://github.com/CLIUtils/CLI11/issues/168
314   -[#179]: https://github.com/CLIUtils/CLI11/pull/179
315   -
316   -
317   -## Version 1.6.1: Platform fixes
318   -
319   -This version provides a few fixes for special cases, such as mixing with `Windows.h` and better defaults
320   -for systems like Hunter. The one new feature is the ability to produce "branded" single file output for
321   -providing custom namespaces or custom macro names.
  280 +This version provides a quick patch for a (correct) warning from GCC 8 for the windows options code.
322 281  
323   -* Added fix and test for including Windows.h [#145][]
324   -* No longer build single file by default if main project, supports systems stuck on Python 2.6 [#149][], [#151][]
325   -* Branding support for single file output [#150][]
  282 +* Fix for Windows style option parsing [#201][]
  283 +* Improve `add_subcommand` when throwing an exception [#204][]
  284 +* Better metadata for Conan package [#202][]
326 285  
327   -[#145]: https://github.com/CLIUtils/CLI11/pull/145
328   -[#149]: https://github.com/CLIUtils/CLI11/pull/149
329   -[#150]: https://github.com/CLIUtils/CLI11/pull/150
330   -[#151]: https://github.com/CLIUtils/CLI11/pull/151
  286 +[#201]: https://github.com/CLIUtils/CLI11/pull/201
  287 +[#202]: https://github.com/CLIUtils/CLI11/pull/202
  288 +[#204]: https://github.com/CLIUtils/CLI11/pull/204
331 289  
332 290 ## Version 1.6: Formatting help
333 291  
... ... @@ -349,7 +307,6 @@ Changes to the help system (most normal users will not notice this):
349 307 * Added getters for the missing parts of options (help no longer uses any private parts).
350 308 * Help flags now use new `short_circuit` property to simplify parsing. [#121][]
351 309  
352   -
353 310 New for Config file reading and writing [#121][]:
354 311  
355 312 * Overridable, bidirectional Config.
... ... @@ -360,7 +317,6 @@ New for Config file reading and writing [#121][]:
360 317 * Added `ConfigItem`.
361 318 * Added an example of a custom config format using [nlohmann/json]. [#138]
362 319  
363   -
364 320 Validators are now much more powerful [#118][], all built in validators upgraded to the new form:
365 321  
366 322 * A subclass of `CLI::Validator` is now also accepted.
... ... @@ -413,33 +369,43 @@ Backend and testing changes:
413 369  
414 370 [nlohmann/json]: https://github.com/nlohmann/json
415 371  
416   -### Version 1.5.4: Optionals
417   -This version fixes the optional search in the single file version; some macros were not yet defined when it did the search. You can define the `CLI11_*_OPTIONAL` macros to 0 if needed to eliminate the search.
418   -
419   -### Version 1.5.3: Compiler compatibility
420   -This version fixes older AppleClang compilers by removing the optimization for casting. The minimum version of Boost Optional supported has been clarified to be 1.58. CUDA 7.0 NVCC is now supported.
  372 +### Version 1.6.1: Platform fixes
421 373  
422   -### Version 1.5.2: LICENSE in single header mode
  374 +This version provides a few fixes for special cases, such as mixing with `Windows.h` and better defaults
  375 +for systems like Hunter. The one new feature is the ability to produce "branded" single file output for
  376 +providing custom namespaces or custom macro names.
423 377  
424   -This is a quick patch release that makes LICENSE part of the single header file, making it easier to include. Minor cleanup from codacy. No significant code changes from 1.5.1.
  378 +* Added fix and test for including Windows.h [#145][]
  379 +* No longer build single file by default if main project, supports systems stuck on Python 2.6 [#149][], [#151][]
  380 +* Branding support for single file output [#150][]
425 381  
426   -### Version 1.5.1: Access
  382 +[#145]: https://github.com/CLIUtils/CLI11/pull/145
  383 +[#149]: https://github.com/CLIUtils/CLI11/pull/149
  384 +[#150]: https://github.com/CLIUtils/CLI11/pull/150
  385 +[#151]: https://github.com/CLIUtils/CLI11/pull/151
427 386  
428   -This patch release adds better access to the App programmatically, to assist with writing custom converters to other formats. It also improves the help output, and uses a new feature in CLI11 1.5 to fix an old "quirk" in the way unlimited options and positionals interact.
  387 +### Version 1.6.2: Help-all
429 388  
430   -* Make mixing unlimited positionals and options more intuitive [#102][]
431   -* Add missing getters `get_options` and `get_description` to App [#105][]
432   -* The app name now can be set, and will override the auto name if present [#105][]
433   -* Add `(REQUIRED)` for required options [#104][]
434   -* Print simple name for Needs/Excludes [#104][]
435   -* Use Needs instead of Requires in help print [#104][]
436   -* Groups now are listed in the original definition order [#106][]
  389 +This version fixes some formatting bugs with help-all. It also adds fixes for several warnings, including an experimental optional error on Clang 7. Several smaller fixes.
437 390  
438   -[#102]: https://github.com/CLIUtils/CLI11/issues/102
439   -[#104]: https://github.com/CLIUtils/CLI11/pull/104
440   -[#105]: https://github.com/CLIUtils/CLI11/pull/105
441   -[#106]: https://github.com/CLIUtils/CLI11/pull/106
  391 +* Fixed help-all formatting [#163][]
  392 + * Printing help-all on nested command now fixed (App)
  393 + * Missing space after help-all restored (Default formatter)
  394 + * More detail printed on help all (Default formatter)
  395 + * Help-all subcommands get indented with inner blank lines removed (Default formatter)
  396 + * `detail::find_and_replace` added to utilities
  397 +* Fixed CMake install as subproject with `CLI11_INSTALL` flag. [#156][]
  398 +* Fixed warning about local variable hiding class member with MSVC [#157][]
  399 +* Fixed compile error with default settings on Clang 7 and libc++ [#158][]
  400 +* Fixed special case of `--help` on subcommands (general fix planned for 1.7) [#168][]
  401 +* Removing an option with links [#179][]
442 402  
  403 +[#156]: https://github.com/CLIUtils/CLI11/issues/156
  404 +[#157]: https://github.com/CLIUtils/CLI11/issues/157
  405 +[#158]: https://github.com/CLIUtils/CLI11/issues/158
  406 +[#163]: https://github.com/CLIUtils/CLI11/pull/163
  407 +[#168]: https://github.com/CLIUtils/CLI11/issues/168
  408 +[#179]: https://github.com/CLIUtils/CLI11/pull/179
443 409  
444 410 ## Version 1.5: Optionals
445 411  
... ... @@ -474,6 +440,34 @@ Other, non-user facing changes:
474 440 [#99]: https://github.com/CLIUtils/CLI11/pull/99
475 441 [#100]: https://github.com/CLIUtils/CLI11/pull/100
476 442  
  443 +### Version 1.5.1: Access
  444 +
  445 +This patch release adds better access to the App programmatically, to assist with writing custom converters to other formats. It also improves the help output, and uses a new feature in CLI11 1.5 to fix an old "quirk" in the way unlimited options and positionals interact.
  446 +
  447 +* Make mixing unlimited positionals and options more intuitive [#102][]
  448 +* Add missing getters `get_options` and `get_description` to App [#105][]
  449 +* The app name now can be set, and will override the auto name if present [#105][]
  450 +* Add `(REQUIRED)` for required options [#104][]
  451 +* Print simple name for Needs/Excludes [#104][]
  452 +* Use Needs instead of Requires in help print [#104][]
  453 +* Groups now are listed in the original definition order [#106][]
  454 +
  455 +[#102]: https://github.com/CLIUtils/CLI11/issues/102
  456 +[#104]: https://github.com/CLIUtils/CLI11/pull/104
  457 +[#105]: https://github.com/CLIUtils/CLI11/pull/105
  458 +[#106]: https://github.com/CLIUtils/CLI11/pull/106
  459 +
  460 +### Version 1.5.2: LICENSE in single header mode
  461 +
  462 +This is a quick patch release that makes LICENSE part of the single header file, making it easier to include. Minor cleanup from codacy. No significant code changes from 1.5.1.
  463 +
  464 +### Version 1.5.3: Compiler compatibility
  465 +
  466 +This version fixes older AppleClang compilers by removing the optimization for casting. The minimum version of Boost Optional supported has been clarified to be 1.58. CUDA 7.0 NVCC is now supported.
  467 +
  468 +### Version 1.5.4: Optionals
  469 +
  470 +This version fixes the optional search in the single file version; some macros were not yet defined when it did the search. You can define the `CLI11_*_OPTIONAL` macros to 0 if needed to eliminate the search.
477 471  
478 472 ## Version 1.4: More feedback
479 473  
... ... @@ -539,7 +533,7 @@ favorite CLI programs. Error messages and help messages are better and more flex
539 533 * Single internal arg parse function [#56](https://github.com/CLIUtils/CLI11/pull/56)
540 534 * Allow options to be disabled from INI file, rename `add_config` to `set_config` [#60](https://github.com/CLIUtils/CLI11/pull/60)
541 535  
542   -> ### Converting from CLI11 1.2:
  536 +> ### Converting from CLI11 1.2
543 537 >
544 538 > * `app.parse` no longer returns a vector. Instead, use `app.remaining(true)`.
545 539 > * `"hidden"` is no longer a special group name, instead use `""`
... ...
README.md
... ... @@ -8,7 +8,7 @@
8 8 [![Actions Status][actions-badge]][actions-link]
9 9 [![Code Coverage][codecov-badge]][codecov]
10 10 [![Codacy Badge][codacy-badge]][codacy-link]
11   -[![Join the chat at https://gitter.im/CLI11gitter/Lobby][gitter-badge]][gitter]
  11 +[![Gitter chat][gitter-badge]][gitter]
12 12 [![License: BSD][license-badge]](./LICENSE)
13 13 [![Latest release][releases-badge]][github releases]
14 14 [![DOI][doi-badge]][doi-link]
... ... @@ -24,38 +24,38 @@ CLI11 is a command line parser for C++11 and beyond that provides a rich feature
24 24  
25 25 ## Table of Contents
26 26  
27   -- [Background](#background)
28   - - [Introduction](#introduction)
29   - - [Why write another CLI parser?](#why-write-another-cli-parser)
30   - - [Other parsers](#other-parsers)
31   - - [Features not supported by this library](#features-not-supported-by-this-library)
32   -- [Install](#install)
33   -- [Usage](#usage)
34   - - [Adding options](#adding-options)
35   - - [Option types](#option-types)
36   - - [Example](#example)
37   - - [Option options](#option-options)
38   - - [Validators](#validators)
39   - - [Transforming Validators](#transforming-validators)
40   - - [Validator operations](#validator-operations)
41   - - [Custom Validators](#custom-validators)
42   - - [Querying Validators](#querying-validators)
43   - - [Getting Results](#getting-results)
44   - - [Subcommands](#subcommands)
45   - - [Subcommand options](#subcommand-options)
46   - - [Option groups](#option-groups)
47   - - [Callbacks](#callbacks)
48   - - [Configuration file](#configuration-file)
49   - - [Inheriting defaults](#inheriting-defaults)
50   - - [Formatting](#formatting)
51   - - [Subclassing](#subclassing)
52   - - [How it works](#how-it-works)
53   - - [Utilities](#utilities)
54   - - [Other libraries](#other-libraries)
55   -- [API](#api)
56   -- [Examples](#Examples)
57   -- [Contribute](#contribute)
58   -- [License](#license)
  27 +* [Background](#background)
  28 + * [Introduction](#introduction)
  29 + * [Why write another CLI parser?](#why-write-another-cli-parser)
  30 + * [Other parsers](#other-parsers)
  31 + * [Features not supported by this library](#features-not-supported-by-this-library)
  32 +* [Install](#install)
  33 +* [Usage](#usage)
  34 + * [Adding options](#adding-options)
  35 + * [Option types](#option-types)
  36 + * [Example](#example)
  37 + * [Option options](#option-options)
  38 + * [Validators](#validators)
  39 + * [Transforming Validators](#transforming-validators)
  40 + * [Validator operations](#validator-operations)
  41 + * [Custom Validators](#custom-validators)
  42 + * [Querying Validators](#querying-validators)
  43 + * [Getting Results](#getting-results)
  44 + * [Subcommands](#subcommands)
  45 + * [Subcommand options](#subcommand-options)
  46 + * [Option groups](#option-groups)
  47 + * [Callbacks](#callbacks)
  48 + * [Configuration file](#configuration-file)
  49 + * [Inheriting defaults](#inheriting-defaults)
  50 + * [Formatting](#formatting)
  51 + * [Subclassing](#subclassing)
  52 + * [How it works](#how-it-works)
  53 + * [Utilities](#utilities)
  54 + * [Other libraries](#other-libraries)
  55 +* [API](#api)
  56 +* [Examples](#Examples)
  57 +* [Contribute](#contribute)
  58 +* [License](#license)
59 59  
60 60 Features that were added in the last released major version are marked with "🆕". Features only available in master are marked with "🚧".
61 61  
... ... @@ -73,21 +73,21 @@ You can be notified when new releases are made by subscribing to &lt;https://github
73 73  
74 74 An acceptable CLI parser library should be all of the following:
75 75  
76   -- Easy to include (i.e., header only, one file if possible, **no external requirements**).
77   -- Short, simple syntax: This is one of the main reasons to use a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability.
78   -- C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.4+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+.
79   -- Work on Linux, macOS, and Windows.
80   -- Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][].
81   -- Clear help printing.
82   -- Nice error messages.
83   -- Standard shell idioms supported naturally, like grouping flags, a positional separator, etc.
84   -- Easy to execute, with help, parse errors, etc. providing correct exit and details.
85   -- Easy to extend as part of a framework that provides "applications" to users.
86   -- Usable subcommand syntax, with support for multiple subcommands, nested subcommands, option groups, and optional fallthrough (explained later).
87   -- Ability to add a configuration file (`TOML`, `INI`, or custom format), and produce it as well.
88   -- Produce real values that can be used directly in code, not something you have pay compute time to look up, for HPC applications.
89   -- Work with standard types, simple custom types, and extensible to exotic types.
90   -- Permissively licensed.
  76 +* Easy to include (i.e., header only, one file if possible, **no external requirements**).
  77 +* Short, simple syntax: This is one of the main reasons to use a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability.
  78 +* C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.4+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+.
  79 +* Work on Linux, macOS, and Windows.
  80 +* Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][].
  81 +* Clear help printing.
  82 +* Nice error messages.
  83 +* Standard shell idioms supported naturally, like grouping flags, a positional separator, etc.
  84 +* Easy to execute, with help, parse errors, etc. providing correct exit and details.
  85 +* Easy to extend as part of a framework that provides "applications" to users.
  86 +* Usable subcommand syntax, with support for multiple subcommands, nested subcommands, option groups, and optional fallthrough (explained later).
  87 +* Ability to add a configuration file (`TOML`, `INI`, or custom format), and produce it as well.
  88 +* Produce real values that can be used directly in code, not something you have pay compute time to look up, for HPC applications.
  89 +* Work with standard types, simple custom types, and extensible to exotic types.
  90 +* Permissively licensed.
91 91  
92 92 ### Other parsers
93 93  
... ... @@ -127,32 +127,36 @@ So, this library was designed to provide a great syntax, good compiler compatibi
127 127  
128 128 There are some other possible "features" that are intentionally not supported by this library:
129 129  
130   -- Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library.
131   -- Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw.
132   -- Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet.
133   -- Wide strings / unicode: Since this uses the standard library only, it might be hard to properly implement, but I would be open to suggestions in how to do this.
  130 +* Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library.
  131 +* Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw.
  132 +* Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet.
  133 +* Wide strings / unicode: Since this uses the standard library only, it might be hard to properly implement, but I would be open to suggestions in how to do this.
134 134  
135 135 ## Install
136 136  
137 137 To use, there are several methods:
138 138  
139   -1. All-in-one local header: Copy `CLI11.hpp` from the [most recent release][github releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately.
140   -2. All-in-one global header: Like above, but copying the file to a shared folder location like `/opt/CLI11`. Then, the C++ include path has to be extended to point at this folder. With CMake, use `include_directories(/opt/CLI11)`
141   -3. Local headers and target: Use `CLI/*.hpp` files. You could check out the repository as a git submodule, for example. With CMake, you can use `add_subdirectory` and the `CLI11::CLI11` interface target when linking. If not using a submodule, you must ensure that the copied files are located inside the same tree directory than your current project, to prevent an error with CMake and `add_subdirectory`.
142   -4. Global headers: Use `CLI/*.hpp` files stored in a shared folder. You could check out the git repository in a system-wide folder, for example `/opt/`. With CMake, you could add to the include path via:
  139 +* All-in-one local header: Copy `CLI11.hpp` from the [most recent release][github releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately.
  140 +* All-in-one global header: Like above, but copying the file to a shared folder location like `/opt/CLI11`. Then, the C++ include path has to be extended to point at this folder. With CMake, use `include_directories(/opt/CLI11)`
  141 +* Local headers and target: Use `CLI/*.hpp` files. You could check out the repository as a git submodule, for example. With CMake, you can use `add_subdirectory` and the `CLI11::CLI11` interface target when linking. If not using a submodule, you must ensure that the copied files are located inside the same tree directory than your current project, to prevent an error with CMake and `add_subdirectory`.
  142 +* Global headers: Use `CLI/*.hpp` files stored in a shared folder. You could check out the git repository in a system-wide folder, for example `/opt/`. With CMake, you could add to the include path via:
  143 +
143 144 ```bash
144 145 if(NOT DEFINED CLI11_DIR)
145 146 set (CLI11_DIR "/opt/CLI11" CACHE STRING "CLI11 git repository")
146 147 endif()
147 148 include_directories(${CLI11_DIR}/include)
148 149 ```
  150 +
149 151 And then in the source code (adding several headers might be needed to prevent linker errors):
  152 +
150 153 ```cpp
151 154 #include "CLI/App.hpp"
152 155 #include "CLI/Formatter.hpp"
153 156 #include "CLI/Config.hpp"
154 157 ```
155   -5. Global headers and target: configuring and installing the project is required for linking CLI11 to your project in the same way as you would do with any other external library. With CMake, this step allows using `find_package(CLI11 CONFIG REQUIRED)` and then using the `CLI11::CLI11` target when linking. If `CMAKE_INSTALL_PREFIX` was changed during install to a specific folder like `/opt/CLI11`, then you have to pass `-DCLI11_DIR=/opt/CLI11` when building your current project. You can also use [Conan.io][conan-link] or [Hunter][].
  158 +
  159 +* Global headers and target: configuring and installing the project is required for linking CLI11 to your project in the same way as you would do with any other external library. With CMake, this step allows using `find_package(CLI11 CONFIG REQUIRED)` and then using the `CLI11::CLI11` target when linking. If `CMAKE_INSTALL_PREFIX` was changed during install to a specific folder like `/opt/CLI11`, then you have to pass `-DCLI11_DIR=/opt/CLI11` when building your current project. You can also use [Conan.io][conan-link] or [Hunter][].
156 160 (These are just conveniences to allow you to use your favorite method of managing packages; it's just header only so including the correct path and
157 161 using C++11 is all you really need.)
158 162  
... ... @@ -315,14 +319,13 @@ app.add_flag(&quot;-1{1},-2{2},-3{3}&quot;,result,&quot;numerical flag&quot;)
315 319  
316 320 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.
317 321  
318   -
319 322 On a `C++14` compiler, you can pass a callback function directly to `.add_flag`, while in C++11 mode you'll need to use `.add_flag_function` if you want a callback function. The function will be given the number of times the flag was passed. You can throw a relevant `CLI::ParseError` to signal a failure.
320 323  
321 324 #### Example
322 325  
323   -- `"one,-o,--one"`: Valid as long as not a flag, would create an option that can be specified positionally, or with `-o` or `--one`
324   -- `"this"` Can only be passed positionally
325   -- `"-a,-b,-c"` No limit to the number of non-positional option names
  326 +* `"one,-o,--one"`: Valid as long as not a flag, would create an option that can be specified positionally, or with `-o` or `--one`
  327 +* `"this"` Can only be passed positionally
  328 +* `"-a,-b,-c"` No limit to the number of non-positional option names
326 329  
327 330 The add commands return a pointer to an internally stored `Option`.
328 331 This option can be used directly to check for the count (`->count()`) after parsing to avoid a string based lookup.
... ... @@ -331,57 +334,57 @@ This option can be used directly to check for the count (`-&gt;count()`) after pars
331 334  
332 335 Before parsing, you can set the following options:
333 336  
334   -- `->required()`: The program will quit if this option is not present. This is `mandatory` in Plumbum, but required options seems to be a more standard term. For compatibility, `->mandatory()` also works.
335   -- `->expected(N)`: Take `N` values instead of as many as possible, only for vector args. If negative, require at least `-N`; end with `--` or another recognized option or subcommand.
336   -- `->type_name(typename)`: Set the name of an Option's type (`type_name_fn` allows a function instead)
337   -- `->type_size(N)`: Set the intrinsic size of an option. The parser will require multiples of this number if negative.
338   -- `->needs(opt)`: This option requires another option to also be present, opt is an `Option` pointer.
339   -- `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer.
340   -- `->envname(name)`: Gets the value from the environment if present and not passed on the command line.
341   -- `->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).
342   -- `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments).
343   -- `->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
344   -- `->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.
345   -- `->allow_extra_args(true/false)`: 🆕 If set to true the option will take an unlimited number of arguments like a vector, if false it will limit the number of arguments to the size of the type used in the option. Default value depends on the nature of the type use, containers default to true, others default to false.
346   -- `->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.
347   -- `->description(str)`: Set/change the description.
348   -- `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`,`->take_all()`, 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).
349   -- `->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
350   -- `->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.
351   -- `->transform(std::string(std::string &), validator_name="",validator_description=")`: Converts the input string into the output string, in-place in the parsed options.
352   -- `->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.
353   -- `->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.
354   -- `->configurable(false)`: Disable this option from being in a configuration file.
355   - `->capture_default_str()`: Store the current value attached and display it in the help string.
356   -- `->default_function(std::string())`: Advanced: Change the function that `capture_default_str()` uses.
357   -- `->always_capture_default()`: Always run `capture_default_str()` when creating new options. Only useful on an App's `option_defaults`.
358   -- `->default_str(string)`: Set the default string directly. This string will also be used as a default value if no arguments are passed and the value is requested.
359   -- `->default_val(value)`: Generate the default string from a value and validate that the value is also valid. For options that assign directly to a value type the value in that type is also updated. Value must be convertible to a string(one of known types or have a stream operator).
360   -- `->option_text(string)`: Sets the text between the option name and description.
361   -
  337 +* `->required()`: The program will quit if this option is not present. This is `mandatory` in Plumbum, but required options seems to be a more standard term. For compatibility, `->mandatory()` also works.
  338 +* `->expected(N)`: Take `N` values instead of as many as possible, only for vector args. If negative, require at least `-N`; end with `--` or another recognized option or subcommand.
  339 +* `->type_name(typename)`: Set the name of an Option's type (`type_name_fn` allows a function instead)
  340 +* `->type_size(N)`: Set the intrinsic size of an option. The parser will require multiples of this number if negative.
  341 +* `->needs(opt)`: This option requires another option to also be present, opt is an `Option` pointer.
  342 +* `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer.
  343 +* `->envname(name)`: Gets the value from the environment if present and not passed on the command line.
  344 +* `->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).
  345 +* `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments).
  346 +* `->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
  347 +* `->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.
  348 +* `->allow_extra_args(true/false)`: 🆕 If set to true the option will take an unlimited number of arguments like a vector, if false it will limit the number of arguments to the size of the type used in the option. Default value depends on the nature of the type use, containers default to true, others default to false.
  349 +* `->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.
  350 +* `->description(str)`: Set/change the description.
  351 +* `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`,`->take_all()`, 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).
  352 +* `->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
  353 +* `->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.
  354 +* `->transform(std::string(std::string &), validator_name="",validator_description=")`: Converts the input string into the output string, in-place in the parsed options.
  355 +* `->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.
  356 +* `->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.
  357 +* `->configurable(false)`: Disable this option from being in a configuration file.
  358 +* `->capture_default_str()`: Store the current value attached and display it in the help string.
  359 +* `->default_function(std::string())`: Advanced: Change the function that `capture_default_str()` uses.
  360 +* `->always_capture_default()`: Always run `capture_default_str()` when creating new options. Only useful on an App's `option_defaults`.
  361 +* `->default_str(string)`: Set the default string directly. This string will also be used as a default value if no arguments are passed and the value is requested.
  362 +* `->default_val(value)`: Generate the default string from a value and validate that the value is also valid. For options that assign directly to a value type the value in that type is also updated. Value must be convertible to a string(one of known types or have a stream operator).
  363 +* `->option_text(string)`: Sets the text between the option name and description.
362 364  
363 365 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.
364 366  
365 367 On the command line, options can be given as:
366 368  
367   -- `-a` (flag)
368   -- `-abc` (flags can be combined)
369   -- `-f filename` (option)
370   -- `-ffilename` (no space required)
371   -- `-abcf filename` (flags and option can be combined)
372   -- `--long` (long flag)
373   -- `--long_flag=true` (long flag with equals to override default value)
374   -- `--file filename` (space)
375   -- `--file=filename` (equals)
  369 +* `-a` (flag)
  370 +* `-abc` (flags can be combined)
  371 +* `-f filename` (option)
  372 +* `-ffilename` (no space required)
  373 +* `-abcf filename` (flags and option can be combined)
  374 +* `--long` (long flag)
  375 +* `--long_flag=true` (long flag with equals to override default value)
  376 +* `--file filename` (space)
  377 +* `--file=filename` (equals)
376 378  
377 379 If `allow_windows_style_options()` is specified in the application or subcommand options can also be given as:
378   -- `/a` (flag)
379   -- `/f filename` (option)
380   -- `/long` (long flag)
381   -- `/file filename` (space)
382   -- `/file:filename` (colon)
383   -- `/long_flag:false` (long flag with : to override the default value)
384   -= Windows style options do not allow combining short options or values not separated from the short option like with `-` options
  380 +
  381 +* `/a` (flag)
  382 +* `/f filename` (option)
  383 +* `/long` (long flag)
  384 +* `/file filename` (space)
  385 +* `/file:filename` (colon)
  386 +* `/long_flag:false` (long flag with : to override the default value)
  387 + * Windows style options do not allow combining short options or values not separated from the short option like with `-` options
385 388  
386 389 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()`.
387 390  
... ... @@ -437,32 +440,34 @@ will produce a check to ensure a value is between 0 and 10 or 20 and 30.
437 440 will produce a check for a number less than or equal to 0.
438 441  
439 442 ##### Transforming Validators
  443 +
440 444 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.
441   -- `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`
442   -- 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.
443   -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.
444   -Here are some examples
445   -of `IsMember`:
446   -
447   -- `CLI::IsMember({"choice1", "choice2"})`: Select from exact match to choices.
448   -- `CLI::IsMember({"choice1", "choice2"}, CLI::ignore_case, CLI::ignore_underscore)`: Match things like `Choice_1`, too.
449   -- `CLI::IsMember(std::set<int>({2,3,4}))`: Most containers and types work; you just need `std::begin`, `std::end`, and `::value_type`.
450   -- `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.
451   -- `auto p = std::make_shared<std::vector<std::string>>(std::initializer_list<std::string>("one", "two")); CLI::IsMember(p)`: You can modify `p` later.
452   -- 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.
  445 +
  446 +* `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`
  447 +* 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.
  448 +
  449 +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. Here are some examples of `IsMember`:
  450 +
  451 +* `CLI::IsMember({"choice1", "choice2"})`: Select from exact match to choices.
  452 +* `CLI::IsMember({"choice1", "choice2"}, CLI::ignore_case, CLI::ignore_underscore)`: Match things like `Choice_1`, too.
  453 +* `CLI::IsMember(std::set<int>({2,3,4}))`: Most containers and types work; you just need `std::begin`, `std::end`, and `::value_type`.
  454 +* `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.
  455 +* `auto p = std::make_shared<std::vector<std::string>>(std::initializer_list<std::string>("one", "two")); CLI::IsMember(p)`: You can modify `p` later.
  456 +* 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.
  457 +
453 458 After specifying a map of options, you can also specify "filter" just like in `CLI::IsMember`.
454 459 Here are some examples (`Transformer` and `CheckedTransformer` are interchangeable in the examples)
455 460 of `Transformer`:
456 461  
457   -- `CLI::Transformer({{"key1", "map1"},{"key2","map2"}})`: Select from key values and produce map values.
458   -
459   -- `CLI::Transformer(std::map<std::string,int>({"two",2},{"three",3},{"four",4}}))`: most maplike containers work, the `::value_type` needs to produce a pair of some kind.
460   -- `CLI::CheckedTransformer(std::map<std::string, int>({{"one", 1}, {"two", 2}}))`: You can use maps; in `->transform()` these replace the matched key with the value. `CheckedTransformer` also requires that the value either match one of the keys or match one of known outputs.
461   -- `auto p = std::make_shared<CLI::TransformPairs<std::string>>(std::initializer_list<std::pair<std::string,std::string>>({"key1", "map1"},{"key2","map2"})); CLI::Transformer(p)`: You can modify `p` later. `TransformPairs<T>` is an alias for `std::vector<std::pair<<std::string,T>>`
  462 +* `CLI::Transformer({{"key1", "map1"},{"key2","map2"}})`: Select from key values and produce map values.
  463 +* `CLI::Transformer(std::map<std::string,int>({"two",2},{"three",3},{"four",4}}))`: most maplike containers work, the `::value_type` needs to produce a pair of some kind.
  464 +* `CLI::CheckedTransformer(std::map<std::string, int>({{"one", 1}, {"two", 2}}))`: You can use maps; in `->transform()` these replace the matched key with the value. `CheckedTransformer` also requires that the value either match one of the keys or match one of known outputs.
  465 +* `auto p = std::make_shared<CLI::TransformPairs<std::string>>(std::initializer_list<std::pair<std::string,std::string>>({"key1", "map1"},{"key2","map2"})); CLI::Transformer(p)`: You can modify `p` later. `TransformPairs<T>` is an alias for `std::vector<std::pair<<std::string,T>>`
462 466  
463 467 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.
464 468  
465 469 ##### Validator operations
  470 +
466 471 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)`.
467 472 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)`
468 473 The operation function of a Validator can be set via
... ... @@ -519,12 +524,13 @@ opt-&gt;get_validator(index);
519 524 ```
520 525  
521 526 Which will return a validator in the index it is applied which isn't necessarily the order in which was defined. The pointer can be `nullptr` if an invalid index is given.
522   -Validators have a few functions to query the current values
523   -- `get_description()`: Will return a description string
524   -- `get_name()`: Will return the Validator name
525   -- `get_active()`: Will return the current active state, true if the Validator is active.
526   -- `get_application_index()`: Will return the current application index.
527   -- `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.
  527 +Validators have a few functions to query the current values:
  528 +
  529 +* `get_description()`: Will return a description string
  530 +* `get_name()`: Will return the Validator name
  531 +* `get_active()`: Will return the current active state, true if the Validator is active.
  532 +* `get_application_index()`: Will return the current application index.
  533 +* `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.
528 534  
529 535 #### Getting results
530 536  
... ... @@ -614,7 +620,6 @@ There are several options that are supported on the main app and subcommands and
614 620  
615 621 > 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.
616 622  
617   -
618 623 #### Callbacks
619 624  
620 625 A subcommand has three 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.
... ... @@ -629,7 +634,6 @@ auto sub2=app.add_subcommand(&quot;sub2&quot;)-&gt;final_callback(c2)-&gt;preparse_callback(pc2)
629 634 app.preparse_callback( pa);
630 635  
631 636 ... A bunch of other options
632   -
633 637 ```
634 638  
635 639 Then the command line is given as
... ... @@ -638,14 +642,14 @@ Then the command line is given as
638 642 program --opt1 opt1_val sub1 --sub1opt --sub1optb val sub2 --sub2opt sub1 --sub1opt2 sub2 --sub2opt2 val
639 643 ```
640 644  
641   -- `pa` will be called prior to parsing any values with an argument of 13.
642   -- `pc1` will be called immediately after processing the `sub1` command with a value of 10.
643   -- `c1` will be called when the `sub2` command is encountered.
644   -- `pc2` will be called with value of 6 after the `sub2` command is encountered.
645   -- `c1` will be called again after the second `sub2` command is encountered.
646   -- `ac1` will be called after processing of all arguments
647   -- `c2` will be called once after processing all arguments.
648   -- `ac2` will be called last after completing all lower level callbacks have been executed.
  645 +* `pa` will be called prior to parsing any values with an argument of 13.
  646 +* `pc1` will be called immediately after processing the `sub1` command with a value of 10.
  647 +* `c1` will be called when the `sub2` command is encountered.
  648 +* `pc2` will be called with value of 6 after the `sub2` command is encountered.
  649 +* `c1` will be called again after the second `sub2` command is encountered.
  650 +* `ac1` will be called after processing of all arguments
  651 +* `c2` will be called once after processing all arguments.
  652 +* `ac2` will be called last after completing all lower level callbacks have been executed.
649 653  
650 654 A subcommand is considered terminated when one of the following conditions are met.
651 655  
... ... @@ -656,8 +660,6 @@ A subcommand is considered terminated when one of the following conditions are m
656 660  
657 661 Prior to executed a `parse_complete_callback` all contained options are processed before the callback is triggered. If a subcommand with a `parse_complete_callback` is called again, then the contained options are reset, and can be triggered again.
658 662  
659   -
660   -
661 663 #### Option groups
662 664  
663 665 The subcommand method
... ... @@ -695,16 +697,19 @@ CLI::TriggerOff(group2_pointer, disabled_group);
695 697 These functions make use of `preparse_callback`, `enabled_by_default()` and `disabled_by_default`. The triggered group may be a vector of group pointers. These methods should only be used once per group and will override any previous use of the underlying functions. More complex arrangements can be accomplished using similar methodology with a custom `preparse_callback` function that does more.
696 698  
697 699 Additional helper functions `deprecate_option` and `retire_option` are available to deprecate or retire options
  700 +
698 701 ```cpp
699 702 CLI::deprecate_option(option *, replacement_name="");
700 703 CLI::deprecate_option(App,option_name,replacement_name="");
701 704 ```
  705 +
702 706 will specify that the option is deprecated which will display a message in the help and a warning on first usage. Deprecated options function normally but will add a message in the help and display a warning on first use.
703 707  
704 708 ```cpp
705 709 CLI::retire_option(App,option *);
706 710 CLI::retire_option(App,option_name);
707 711 ```
  712 +
708 713 will create an option that does nothing by default and will display a warning on first usage that the option is retired and has no effect. If the option exists it is replaces with a dummy option that takes the same arguments.
709 714  
710 715 If an empty string is passed the option group name the entire group will be hidden in the help results. For example.
... ... @@ -712,6 +717,7 @@ If an empty string is passed the option group name the entire group will be hidd
712 717 ```cpp
713 718 auto hidden_group=app.add_option_group("");
714 719 ```
  720 +
715 721 will create a group such that no options in that group are displayed in the help string.
716 722  
717 723 ### Configuration file
... ... @@ -739,7 +745,9 @@ str_vector = [&quot;one&quot;,&quot;two&quot;,&quot;and three&quot;]
739 745 in_subcommand = Wow
740 746 sub.subcommand = true
741 747 ```
  748 +
742 749 or equivalently in INI format
  750 +
743 751 ```ini
744 752 ; Comments are supported, using a ;
745 753 ; The default section is [default], case insensitive
... ... @@ -879,29 +887,28 @@ The API is [documented here][api-docs]. Also see the [CLI11 tutorial GitBook][gi
879 887  
880 888 Several short examples of different features are included in the repository. A brief description of each is included here
881 889  
882   -- [callback_passthrough](https://github.com/CLIUtils/CLI11/blob/master/examples/callback_passthrough.cpp): Example of directly passing remaining arguments through to a callback function which generates a CLI11 application based on existing arguments.
883   -- [custom_parse](https://github.com/CLIUtils/CLI11/blob/master/examples/custom_parse.cpp): Based on [Issue #566](https://github.com/CLIUtils/CLI11/issues/566), example of custom parser
884   -- [digit_args](https://github.com/CLIUtils/CLI11/blob/master/examples/digit_args.cpp): Based on [Issue #123](https://github.com/CLIUtils/CLI11/issues/123), uses digit flags to pass a value
885   -- [enum](https://github.com/CLIUtils/CLI11/blob/master/examples/enum.cpp): Using enumerations in an option, and the use of [CheckedTransformer](#transforming-validators)
886   -- [enum_ostream](https://github.com/CLIUtils/CLI11/blob/master/examples/enum_ostream.cpp): In addition to the contents of example enum.cpp, this example shows how a custom ostream operator overrides CLI11's enum streaming.
887   -- [formatter](https://github.com/CLIUtils/CLI11/blob/master/examples/formatter.cpp): Illustrating usage of a custom formatter
888   -- [groups](https://github.com/CLIUtils/CLI11/blob/master/examples/groups.cpp): Example using groups of options for help grouping and a the timer helper class
889   -- [inter_argument_order](https://github.com/CLIUtils/CLI11/blob/master/examples/inter_argument_order.cpp): An app to practice mixing unlimited arguments, but still recover the original order.
890   -- [json](https://github.com/CLIUtils/CLI11/blob/master/examples/json.cpp): Using JSON as a config file parser
891   -- [modhelp](https://github.com/CLIUtils/CLI11/blob/master/examples/modhelp.cpp): How to modify the help flag to do something other than default
892   -- [nested](https://github.com/CLIUtils/CLI11/blob/master/examples/nested.cpp): Nested subcommands
893   -- [option_groups](https://github.com/CLIUtils/CLI11/blob/master/examples/option_groups.cpp): illustrating the use of option groups and a required number of options.
894   -based on [Issue #88](https://github.com/CLIUtils/CLI11/issues/88) to set interacting groups of options
895   -- [positional_arity](https://github.com/CLIUtils/CLI11/blob/master/examples/positional_arity.cpp): Illustrating use of `preparse_callback` to handle situations where the number of arguments can determine which should get parsed, Based on [Issue #166](https://github.com/CLIUtils/CLI11/issues/166)
896   -- [positional_validation](https://github.com/CLIUtils/CLI11/blob/master/examples/positional_validation.cpp): Example of how positional arguments are validated using the `validate_positional` flag, also based on [Issue #166](https://github.com/CLIUtils/CLI11/issues/166)
897   -- [prefix_command](https://github.com/CLIUtils/CLI11/blob/master/examples/prefix_command.cpp): illustrating use of the `prefix_command` flag.
898   -- [ranges](https://github.com/CLIUtils/CLI11/blob/master/examples/ranges.cpp): App to demonstrate exclusionary option groups based on [Issue #88](https://github.com/CLIUtils/CLI11/issues/88)
899   -- [shapes](https://github.com/CLIUtils/CLI11/blob/master/examples/shapes.cpp): illustrating how to set up repeated subcommands Based on [gitter discussion](https://gitter.im/CLI11gitter/Lobby?at=5c7af6b965ffa019ea788cd5)
900   -- [simple](https://github.com/CLIUtils/CLI11/blob/master/examples/simple.cpp): a simple example of how to set up a CLI11 Application with different flags and options
901   -- [subcom_help](https://github.com/CLIUtils/CLI11/blob/master/examples/subcom_help.cpp): configuring help for subcommands
902   -- [subcom_partitioned](https://github.com/CLIUtils/CLI11/blob/master/examples/subcom_partitioned.cpp): Example with a timer and subcommands generated separately and added to the main app later.
903   -- [subcommands](https://github.com/CLIUtils/CLI11/blob/master/examples/subcommands.cpp): Short example of subcommands
904   -- [validators](https://github.com/CLIUtils/CLI11/blob/master/examples/validators.cpp): Example illustrating use of validators
  890 +* [callback_passthrough](https://github.com/CLIUtils/CLI11/blob/master/examples/callback_passthrough.cpp): Example of directly passing remaining arguments through to a callback function which generates a CLI11 application based on existing arguments.
  891 +* [custom_parse](https://github.com/CLIUtils/CLI11/blob/master/examples/custom_parse.cpp): Based on [Issue #566](https://github.com/CLIUtils/CLI11/issues/566), example of custom parser
  892 +* [digit_args](https://github.com/CLIUtils/CLI11/blob/master/examples/digit_args.cpp): Based on [Issue #123](https://github.com/CLIUtils/CLI11/issues/123), uses digit flags to pass a value
  893 +* [enum](https://github.com/CLIUtils/CLI11/blob/master/examples/enum.cpp): Using enumerations in an option, and the use of [CheckedTransformer](#transforming-validators)
  894 +* [enum_ostream](https://github.com/CLIUtils/CLI11/blob/master/examples/enum_ostream.cpp): In addition to the contents of example enum.cpp, this example shows how a custom ostream operator overrides CLI11's enum streaming.
  895 +* [formatter](https://github.com/CLIUtils/CLI11/blob/master/examples/formatter.cpp): Illustrating usage of a custom formatter
  896 +* [groups](https://github.com/CLIUtils/CLI11/blob/master/examples/groups.cpp): Example using groups of options for help grouping and a the timer helper class
  897 +* [inter_argument_order](https://github.com/CLIUtils/CLI11/blob/master/examples/inter_argument_order.cpp): An app to practice mixing unlimited arguments, but still recover the original order.
  898 +* [json](https://github.com/CLIUtils/CLI11/blob/master/examples/json.cpp): Using JSON as a config file parser
  899 +* [modhelp](https://github.com/CLIUtils/CLI11/blob/master/examples/modhelp.cpp): How to modify the help flag to do something other than default
  900 +* [nested](https://github.com/CLIUtils/CLI11/blob/master/examples/nested.cpp): Nested subcommands
  901 +* [option_groups](https://github.com/CLIUtils/CLI11/blob/master/examples/option_groups.cpp): Illustrating the use of option groups and a required number of options. Based on [Issue #88](https://github.com/CLIUtils/CLI11/issues/88) to set interacting groups of options
  902 +* [positional_arity](https://github.com/CLIUtils/CLI11/blob/master/examples/positional_arity.cpp): Illustrating use of `preparse_callback` to handle situations where the number of arguments can determine which should get parsed, Based on [Issue #166](https://github.com/CLIUtils/CLI11/issues/166)
  903 +* [positional_validation](https://github.com/CLIUtils/CLI11/blob/master/examples/positional_validation.cpp): Example of how positional arguments are validated using the `validate_positional` flag, also based on [Issue #166](https://github.com/CLIUtils/CLI11/issues/166)
  904 +* [prefix_command](https://github.com/CLIUtils/CLI11/blob/master/examples/prefix_command.cpp): Illustrating use of the `prefix_command` flag.
  905 +* [ranges](https://github.com/CLIUtils/CLI11/blob/master/examples/ranges.cpp): App to demonstrate exclusionary option groups based on [Issue #88](https://github.com/CLIUtils/CLI11/issues/88)
  906 +* [shapes](https://github.com/CLIUtils/CLI11/blob/master/examples/shapes.cpp): Illustrating how to set up repeated subcommands Based on [gitter discussion](https://gitter.im/CLI11gitter/Lobby?at=5c7af6b965ffa019ea788cd5)
  907 +* [simple](https://github.com/CLIUtils/CLI11/blob/master/examples/simple.cpp): A simple example of how to set up a CLI11 Application with different flags and options
  908 +* [subcom_help](https://github.com/CLIUtils/CLI11/blob/master/examples/subcom_help.cpp): Configuring help for subcommands
  909 +* [subcom_partitioned](https://github.com/CLIUtils/CLI11/blob/master/examples/subcom_partitioned.cpp): Example with a timer and subcommands generated separately and added to the main app later.
  910 +* [subcommands](https://github.com/CLIUtils/CLI11/blob/master/examples/subcommands.cpp): Short example of subcommands
  911 +* [validators](https://github.com/CLIUtils/CLI11/blob/master/examples/validators.cpp): Example illustrating use of validators
905 912  
906 913 ## Contribute
907 914  
... ... @@ -910,7 +917,6 @@ This readme roughly follows the [Standard Readme Style][] and includes a mention
910 917  
911 918 This project was created by [Henry Schreiner](https://github.com/henryiii) and major features were added by [Philip Top](https://github.com/phlptp). Special thanks to all the contributors ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
912 919  
913   -
914 920 <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
915 921 <!-- prettier-ignore-start -->
916 922 <!-- markdownlint-disable -->
... ... @@ -987,7 +993,6 @@ This project was created by [Henry Schreiner](https://github.com/henryiii) and m
987 993 <!-- prettier-ignore-end -->
988 994 <!-- ALL-CONTRIBUTORS-LIST:END -->
989 995  
990   -
991 996 This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
992 997  
993 998 ## License
... ...
book/chapters/advanced-topics.md
1 1 # Advanced topics
2 2  
3   -
4 3 ## Environment variables
5 4  
6 5 Environment variables can be used to fill in the value of an option:
... ... @@ -9,6 +8,7 @@ Environment variables can be used to fill in the value of an option:
9 8 std::string opt;
10 9 app.add_option("--my_option", opt)->envname("MY_OPTION");
11 10 ```
  11 +
12 12 If not given on the command line, the environment variable will be checked and read from if it exists. All the standard tools, like default and required, work as expected.
13 13 If passed on the command line, this will ignore the environment variable.
14 14  
... ... @@ -55,7 +55,7 @@ add_option(CLI::App &amp;app, std::string name, cx &amp;variable, std::string descriptio
55 55  
56 56 Then you could use it like this:
57 57  
58   -```
  58 +```cpp
59 59 std::complex<double> comp{0, 0};
60 60 add_option(app, "-c,--complex", comp);
61 61 ```
... ... @@ -89,7 +89,6 @@ template &lt;typename T&gt; std::istringstream &amp;operator&gt;&gt;(std::istringstream &amp;in, boo
89 89  
90 90 This is an example of how to use the system only; if you are just looking for a way to activate `boost::optional` support on older compilers, you should define `CLI11_BOOST_OPTIONAL` before including a CLI11 file, you'll get the `boost::optional` support.
91 91  
92   -
93 92 ## Custom converters and type names: std::chrono example
94 93  
95 94 An example of adding a custom converter and typename for `std::chrono` follows:
... ... @@ -97,40 +96,40 @@ An example of adding a custom converter and typename for `std::chrono` follows:
97 96 ```cpp
98 97 namespace CLI
99 98 {
100   - template <typename T, typename R>
101   - std::istringstream &operator>>(std::istringstream &in, std::chrono::duration<T,R> &val)
102   - {
103   - T v;
104   - in >> v;
105   - val = std::chrono::duration<T,R>(v);
106   - return in;
107   - }
108   -
109   - template <typename T, typename R>
110   - std::stringstream &operator<<(std::stringstream &in, std::chrono::duration<T,R> &val)
111   - {
112   - in << val.count();
113   - return in;
114   - }
  99 + template <typename T, typename R>
  100 + std::istringstream &operator>>(std::istringstream &in, std::chrono::duration<T,R> &val)
  101 + {
  102 + T v;
  103 + in >> v;
  104 + val = std::chrono::duration<T,R>(v);
  105 + return in;
  106 + }
  107 +
  108 + template <typename T, typename R>
  109 + std::stringstream &operator<<(std::stringstream &in, std::chrono::duration<T,R> &val)
  110 + {
  111 + in << val.count();
  112 + return in;
  113 + }
115 114 }
116 115  
117 116 #include <CLI/CLI.hpp>
118 117  
119 118 namespace CLI
120 119 {
121   - namespace detail
122   - {
123   - template <>
124   - constexpr const char *type_name<std::chrono::hours>()
125   - {
126   - return "TIME [H]";
127   - }
128   -
129   - template <>
130   - constexpr const char *type_name<std::chrono::minutes>()
131   - {
132   - return "TIME [MIN]";
133   - }
  120 + namespace detail
  121 + {
  122 + template <>
  123 + constexpr const char *type_name<std::chrono::hours>()
  124 + {
  125 + return "TIME [H]";
  126 + }
  127 +
  128 + template <>
  129 + constexpr const char *type_name<std::chrono::minutes>()
  130 + {
  131 + return "TIME [MIN]";
  132 + }
134 133 }
135 134 }
136 135 ```
... ...
book/chapters/an-advanced-example.md
1 1 # Making a git clone
2 2  
3   -
4   -
5 3 Let's try our hand at a little `git` clone, called `geet`. It will just print it's intent, rather than running actual code, since it's just a demonstration. Let's start by adding an app and requiring 1 subcommand to run:
6 4  
7 5 [include:"Intro"](../code/geet.cpp)
... ...
book/chapters/config.md
... ... @@ -5,36 +5,42 @@
5 5 You can tell your app to allow configure files with `set_config("--config")`. There are arguments: the first is the option name. If empty, it will clear the config flag. The second item is the default file name. If that is specified, the config will try to read that file. The third item is the help string, with a reasonable default, and the final argument is a boolean (default: false) that indicates that the configuration file is required and an error will be thrown if the file is not found and this is set to true.
6 6  
7 7 ### Extra fields
  8 +
8 9 Sometimes configuration files are used for multiple purposes so CLI11 allows options on how to deal with extra fields
9 10  
10 11 ```cpp
11 12 app.allow_config_extras(true);
12 13 ```
  14 +
13 15 will allow capture the extras in the extras field of the app. (NOTE: This also sets the `allow_extras` in the app to true)
14 16  
15 17 ```cpp
16 18 app.allow_config_extras(false);
17 19 ```
  20 +
18 21 will generate an error if there are any extra fields
  22 +for slightly finer control there is a scoped enumeration of the modes or
19 23  
20   -for slightly finer control there is a scoped enumeration of the modes
21   -or
22 24 ```cpp
23 25 app.allow_config_extras(CLI::config_extras_mode::ignore);
24 26 ```
  27 +
25 28 will completely ignore extra parameters in the config file. This mode is the default.
26 29  
27 30 ```cpp
28 31 app.allow_config_extras(CLI::config_extras_mode::capture);
29 32 ```
  33 +
30 34 will store the unrecognized options in the app extras fields. This option is the closest equivalent to `app.allow_config_extras(true);` with the exception that it does not also set the `allow_extras` flag so using this option without also setting `allow_extras(true)` will generate an error which may or may not be the desired behavior.
31 35  
32 36 ```cpp
33 37 app.allow_config_extras(CLI::config_extras_mode::error);
34 38 ```
  39 +
35 40 is equivalent to `app.allow_config_extras(false);`
36 41  
37 42 ### Getting the used configuration file name
  43 +
38 44 If it is needed to get the configuration file name used this can be obtained via
39 45 `app.get_config_ptr()->as<std::string>()` or
40 46 `app["--config"]->as<std::string>()` assuming `--config` was the configuration option name.
... ... @@ -93,7 +99,6 @@ Where X is some positive integer and will allow up to `X` configuration files to
93 99 To print a configuration file from the passed arguments, use `.config_to_str(default_also=false, write_description=false)`, where `default_also` will also show any defaulted arguments, and `write_description` will include option descriptions and the App description
94 100  
95 101 ```cpp
96   -
97 102 CLI::App app;
98 103 app.add_option(...);
99 104 // several other options
... ... @@ -105,7 +110,6 @@ To print a configuration file from the passed arguments, use `.config_to_str(def
105 110 if a prefix is needed to print before the options, for example to print a config for just a subcommand, the config formatter can be obtained directly.
106 111  
107 112 ```cpp
108   -
109 113 auto fmtr=app.get_config_formatter();
110 114 //std::string to_config(const App *app, bool default_also, bool write_description, std::string prefix)
111 115 fmtr->to_config(&app,true,true,"sub.");
... ... @@ -113,7 +117,9 @@ if a prefix is needed to print before the options, for example to print a config
113 117 ```
114 118  
115 119 ### Customization of configure file output
  120 +
116 121 The default config parser/generator has some customization points that allow variations on the TOML format. The default formatter has a base configuration that matches the TOML format. It defines 5 characters that define how different aspects of the configuration are handled
  122 +
117 123 ```cpp
118 124 /// the character used for comments
119 125 char commentChar = '#';
... ... @@ -129,12 +135,12 @@ char valueDelimiter = &#39;=&#39;;
129 135  
130 136 These can be modified via setter functions
131 137  
132   -- ` ConfigBase *comment(char cchar)` Specify the character to start a comment block
133   -- `ConfigBase *arrayBounds(char aStart, char aEnd)` Specify the start and end characters for an array
134   -- `ConfigBase *arrayDelimiter(char aSep)` Specify the delimiter character for an array
135   -- `ConfigBase *valueSeparator(char vSep)` Specify the delimiter between a name and value
  138 +* `ConfigBase *comment(char cchar)`: Specify the character to start a comment block
  139 +* `ConfigBase *arrayBounds(char aStart, char aEnd)`: Specify the start and end characters for an array
  140 +* `ConfigBase *arrayDelimiter(char aSep)`: Specify the delimiter character for an array
  141 +* `ConfigBase *valueSeparator(char vSep)`: Specify the delimiter between a name and value
136 142  
137   -For example to specify reading a configure file that used `:` to separate name and values
  143 +For example, to specify reading a configure file that used `:` to separate name and values:
138 144  
139 145 ```cpp
140 146 auto config_base=app.get_config_formatter_base();
... ... @@ -142,9 +148,11 @@ config_base-&gt;valueSeparator(&#39;:&#39;);
142 148 ```
143 149  
144 150 The default configuration file will read INI files, but will write out files in the TOML format. To specify outputting INI formatted files use
  151 +
145 152 ```cpp
146 153 app.config_formatter(std::make_shared<CLI::ConfigINI>());
147 154 ```
  155 +
148 156 which makes use of a predefined modification of the ConfigBase class which TOML also uses. If a custom formatter is used that is not inheriting from the from ConfigBase class `get_config_formatter_base() will return a nullptr if RTTI is on (usually the default), or garbage if RTTI is off, so some care must be exercised in its use with custom configurations.
149 157  
150 158 ## Custom formats
... ... @@ -166,16 +174,17 @@ app.config_formatter(std::make_shared&lt;NewConfig&gt;());
166 174  
167 175 See [`examples/json.cpp`](https://github.com/CLIUtils/CLI11/blob/master/examples/json.cpp) for a complete JSON config example.
168 176  
169   -
170 177 ## Triggering Subcommands
  178 +
171 179 Configuration files can be used to trigger subcommands if a subcommand is set to configure. By default configuration file just set the default values of a subcommand. But if the `configure()` option is set on a subcommand then the if the subcommand is utilized via a `[subname]` block in the configuration file it will act as if it were called from the command line. Subsubcommands can be triggered via [subname.subsubname]. Using the `[[subname]]` will be as if the subcommand were triggered multiple times from the command line. This functionality can allow the configuration file to act as a scripting file.
172 180  
173 181 For custom configuration files this behavior can be triggered by specifying the parent subcommands in the structure and `++` as the name to open a new subcommand scope and `--` to close it. These names trigger the different callbacks of configurable subcommands.
174 182  
175 183 ## Implementation Notes
  184 +
176 185 The config file input works with any form of the option given: Long, short, positional, or the environment variable name. When generating a config file it will create a name in following priority.
177 186  
178   -1. First long name
179   -2. Positional name
180   -3. First short name
181   -4. Environment name
  187 +1. First long name
  188 +2. Positional name
  189 +3. First short name
  190 +4. Environment name
... ...
book/chapters/flags.md
... ... @@ -13,7 +13,6 @@ app.add_flag(&quot;-f&quot;, my_flag, &quot;Optional description&quot;);
13 13  
14 14 This will bind the flag `-f` to the boolean `my_flag`. After the parsing step, `my_flag` will be `false` if the flag was not found on the command line, or `true` if it was. By default, it will be allowed any number of times, but if you explicitly[^1] request `->take_last(false)`, it will only be allowed once; passing something like `./my_app -f -f` or `./my_app -ff` will throw a `ParseError` with a nice help description.
15 15  
16   -
17 16 ## Integer flags
18 17  
19 18 If you want to allow multiple flags, simply use any integer-like instead of a bool:
... ... @@ -70,7 +69,6 @@ auto callback = [](int count){std::cout &lt;&lt; &quot;This was called &quot; &lt;&lt; count &lt;&lt; &quot; time
70 69 app.add_flag_function("-c", callback, "Optional description");
71 70 ```
72 71  
73   -
74 72 ## Aliases
75 73  
76 74 The name string, the first item of every `add_` method, can contain as many short and long names as you want, separated by commas. For example, `"-a,--alpha,-b,--beta"` would allow any of those to be recognized on the command line. If you use the same name twice, or if you use the same name in multiple flags, CLI11 will immediately throw a `CLI::ConstructionError` describing your problem (it will not wait until the parsing step).
... ... @@ -122,5 +120,4 @@ Flag int: 3
122 120 Flag plain: 1
123 121 ```
124 122  
125   -
126 123 [^1]: It will not inherit this from the parent defaults, since this is often useful even if you don't want all options to allow multiple passed options.
... ...
book/chapters/formatting.md
... ... @@ -4,13 +4,12 @@
4 4 New in CLI11 1.6
5 5 {% endhint %}
6 6  
7   -## Customizing an existing formatter
  7 +## Customizing an existing formatter
8 8  
9 9 In CLI11, you can control the output of the help printout in full or in part. The default formatter was written in such a way as to be customizable. You can use `app.get_formatter()` to get the current formatter. The formatter you set will be inherited by subcommands that are created after you set the formatter.
10 10  
11 11 There are several configuration options that you can set:
12 12  
13   -
14 13 | Set method | Description | Availability |
15 14 |------------|-------------|--------------|
16 15 | `column_width(width)` | The width of the columns | Both |
... ... @@ -60,7 +59,7 @@ This is a normal printout, with `&lt;&gt;` indicating the methods used to produce each
60 59  
61 60 The `make_groups` print the group name then call `make_option(o)` on the options listed in that group. The normal printout for an option looks like this:
62 61  
63   -```
  62 +```text
64 63 make_option_opts(o)
65 64 ┌───┴────┐
66 65 -n,--name (REQUIRED) This is a description
... ...
book/chapters/options.md
1 1 # Options
2 2  
3 3 ## Simple options
4   -The most versatile addition to a command line program is a option. This is like a flag, but it takes an argument. CLI11 handles all the details for many types of options for you, based on their type. To add an option:
5 4  
  5 +The most versatile addition to a command line program is a option. This is like a flag, but it takes an argument. CLI11 handles all the details for many types of options for you, based on their type. To add an option:
6 6  
7 7 ```cpp
8 8 int int_option{0};
... ... @@ -73,6 +73,7 @@ Vectors will be replaced by the parsed content if the option is given on the com
73 73 A definition of a container for purposes of CLI11 is a type with a `end()`, `insert(...)`, `clear()` and `value_type` definitions. This includes `vector`, `set`, `deque`, `list`, `forward_iist`, `map`, `unordered_map` and a few others from the standard library, and many other containers from the boost library.
74 74  
75 75 ### Containers of containers
  76 +
76 77 Containers of containers are also supported.
77 78  
78 79 ```cpp
... ... @@ -85,6 +86,7 @@ CLI11 inserts a separator sequence at the start of each argument call to separat
85 86 ```bash
86 87 cmd --vec_of_vec 1 2 3 4 %% 1 2
87 88 ```
  89 +
88 90 would then result in a container of size 2 with the first element containing 4 values and the second 2.
89 91  
90 92 This separator is also the only way to get values into something like
... ... @@ -99,7 +101,9 @@ without calling the argument twice.
99 101 Further levels of nesting containers should compile but intermediate layers will only have a single element in the container, so is probably not that useful.
100 102  
101 103 ### Nested types
102   -Types can be nested For example
  104 +
  105 +Types can be nested. For example:
  106 +
103 107 ```cpp
104 108 std::map<int, std::pair<int,std::string>> map;
105 109 app.add_option("--dict", map, "map of pairs");
... ... @@ -111,6 +115,7 @@ will require 3 arguments for each invocation, and multiple sets of 3 arguments c
111 115 std::map<int, std::pair<int,std::vector<std::string>>> map;
112 116 app.add_option("--dict", map, "map of pairs");
113 117 ```
  118 +
114 119 will result in a requirement for 2 integers on each invocation and absorb an unlimited number of strings including 0.
115 120  
116 121 ## Option modifiers
... ... @@ -166,19 +171,19 @@ if(* opt)
166 171  
167 172 One of CLI11's systems to allow customizability without high levels of verbosity is the inheritance system. You can set default values on the parent `App`, and all options and subcommands created from it remember the default values at the point of creation. The default value for Options, specifically, are accessible through the `option_defaults()` method. There are a number of settings that can be set and inherited:
168 173  
169   -* `group`: The group name starts as "Options"
170   -* `required`: If the option must be given. Defaults to `false`. Is ignored for flags.
171   -* `multi_option_policy`: What to do if several copies of an option are passed and one value is expected. Defaults to `CLI::MultiOptionPolicy::Throw`. This is also used for bool flags, but they always are created with the value `CLI::MultiOptionPolicy::TakeLast` regardless of the default, so that multiple bool flags does not cause an error. But you can override that flag by flag.
172   -* `ignore_case`: Allow any mixture of cases for the option or flag name
173   -* `ignore_underscore`: Allow any number of underscores in the option or flag name
174   -* `configurable`: Specify whether an option can be configured through a config file
175   -* `disable_flag_override`: do not allow flag values to be overridden on the command line
176   -* `always_capture_default`: specify that the default values should be automatically captured.
177   -* `delimiter`: A delimiter to use for capturing multiple values in a single command line string (e.g. --flag="flag,-flag2,flag3")
  174 +* `group`: The group name starts as "Options"
  175 +* `required`: If the option must be given. Defaults to `false`. Is ignored for flags.
  176 +* `multi_option_policy`: What to do if several copies of an option are passed and one value is expected. Defaults to `CLI::MultiOptionPolicy::Throw`. This is also used for bool flags, but they always are created with the value `CLI::MultiOptionPolicy::TakeLast` regardless of the default, so that multiple bool flags does not cause an error. But you can override that flag by flag.
  177 +* `ignore_case`: Allow any mixture of cases for the option or flag name
  178 +* `ignore_underscore`: Allow any number of underscores in the option or flag name
  179 +* `configurable`: Specify whether an option can be configured through a config file
  180 +* `disable_flag_override`: do not allow flag values to be overridden on the command line
  181 +* `always_capture_default`: specify that the default values should be automatically captured.
  182 +* `delimiter`: A delimiter to use for capturing multiple values in a single command line string (e.g. --flag="flag,-flag2,flag3")
178 183  
179 184 An example of usage:
180 185  
181   -```
  186 +```cpp
182 187 app.option_defaults()->ignore_case()->group("Required");
183 188  
184 189 app.add_flag("--CaSeLeSs");
... ... @@ -187,17 +192,16 @@ app.get_group() // is &quot;Required&quot;
187 192  
188 193 Groups are mostly for visual organization, but an empty string for a group name will hide the option.
189 194  
190   -
191 195 ### Windows style options
192 196  
193 197 You can also set the app setting `app->allow_windows_style_options()` to allow windows style options to also be recognized on the command line:
194 198  
195   -* `/a` (flag)
196   -* `/f filename` (option)
197   -* `/long` (long flag)
198   -* `/file filename` (space)
199   -* `/file:filename` (colon)
200   -* `/long_flag:false` (long flag with : to override the default value)
  199 +* `/a` (flag)
  200 +* `/f filename` (option)
  201 +* `/long` (long flag)
  202 +* `/file filename` (space)
  203 +* `/file:filename` (colon)
  204 +* `/long_flag:false` (long flag with : to override the default value)
201 205  
202 206 Windows style options do not allow combining short options or values not separated from the short option like with `-` options. You still specify option names in the same manner as on Linux with single and double dashes when you use the `add_*` functions, and the Linux style on the command line will still work. If a long and a short option share the same name, the option will match on the first one defined.
203 207  
... ... @@ -205,15 +209,19 @@ Windows style options do not allow combining short options or values not separat
205 209  
206 210 How an option and its arguments are parsed depends on a set of controls that are part of the option structure. In most circumstances these controls are set automatically based on the type or function used to create the option and the type the arguments are parsed into. The variables define the size of the underlying type (essentially how many strings make up the type), the expected size (how many groups are expected) and a flag indicating if multiple groups are allowed with a single option. And these interact with the `multi_option_policy` when it comes time to parse.
207 211  
208   -### examples
209   -How options manage this is best illustrated through some examples
  212 +### Examples
  213 +
  214 +How options manage this is best illustrated through some examples.
  215 +
210 216 ```cpp
211 217 std::string val;
212 218 app.add_option("--opt",val,"description");
213 219 ```
  220 +
214 221 creates an option that assigns a value to a `std::string` When this option is constructed it sets a type_size min and max of 1. Meaning that the assignment uses a single string. The Expected size is also set to 1 by default, and `allow_extra_args` is set to false. meaning that each time this option is called 1 argument is expected. This would also be the case if val were a `double`, `int` or any other single argument types.
215 222  
216 223 now for example
  224 +
217 225 ```cpp
218 226 std::pair<int, std::string> val;
219 227 app.add_option("--opt",val,"description");
... ... @@ -232,6 +240,7 @@ detects a type size of 1, since the underlying element type is a single string,
232 240 std::vector<std::tuple<int, double, std::string>> val;
233 241 app.add_option("--opt",val,"description");
234 242 ```
  243 +
235 244 gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result.
236 245  
237 246 ```cpp
... ... @@ -248,11 +257,11 @@ app.add_option(&quot;--opt&quot;,val,&quot;description&quot;);
248 257  
249 258 triggers the complex number type which has a min of 1 and max of 2, so 1 or 2 strings can be passed. Complex number conversion supports arguments of the form "1+2j" or "1","2", or "1" "2i". The imaginary number symbols `i` and `j` are interchangeable in this context.
250 259  
251   -
252 260 ```cpp
253 261 std::vector<std::vector<int>> val;
254 262 app.add_option("--opt",val,"description");
255 263 ```
  264 +
256 265 has a type size of 1 to (1<<30).
257 266  
258 267 ### Customization
... ... @@ -264,10 +273,13 @@ std::string val;
264 273 auto opt=app.add_flag("--opt{vvv}",val,"description");
265 274 opt->expected(0,1);
266 275 ```
  276 +
267 277 will create a hybrid option, that can exist on its own in which case the value "vvv" is used or if a value is given that value will be used.
268 278  
269   -There are some additional options that can be specified to modify an option for specific cases
270   -- `->run_callback_for_default()` will specify that the callback should be executed when a default_val is set. This is set automatically when appropriate though it can be turned on or off and any user specified callback for an option will be executed when the default value for an option is set.
  279 +There are some additional options that can be specified to modify an option for specific cases:
  280 +
  281 +* `->run_callback_for_default()` will specify that the callback should be executed when a default_val is set. This is set automatically when appropriate though it can be turned on or off and any user specified callback for an option will be executed when the default value for an option is set.
271 282  
272 283 ## Unusual circumstances
  284 +
273 285 There are a few cases where some things break down in the type system managing options and definitions. Using the `add_option` method defines a lambda function to extract a default value if required. In most cases this either straightforward or a failure is detected automatically and handled. But in a few cases a streaming template is available that several layers down may not actually be defined. The conditions in CLI11 cannot detect this circumstance automatically and will result in compile error. One specific known case is `boost::optional` if the boost optional_io header is included. This header defines a template for all boost optional values even if they do no actually have a streaming operator. For example `boost::optional<std::vector>` does not have a streaming operator but one is detected since it is part of a template. For these cases a secondary method `app->add_option_no_stream(...)` is provided that bypasses this operation completely and should compile in these cases.
... ...
book/chapters/subcommands.md
... ... @@ -53,6 +53,7 @@ Each App has controls to set the number of subcommands you expect. This is contr
53 53 ```cpp
54 54 app.require_subcommand(/* min */ 0, /* max */ 1);
55 55 ```
  56 +
56 57 If you set the max to 0, CLI11 will allow an unlimited number of subcommands. After the (non-unlimited) maximum
57 58 is reached, CLI11 will stop trying to match subcommands. So the if you pass "`one two`" to a command, and both `one`
58 59 and `two` are subcommands, it will depend on the maximum number as to whether the "`two`" is a subcommand or an argument to the
... ...
book/chapters/toolkits.md
... ... @@ -2,7 +2,7 @@
2 2  
3 3 CLI11 was designed to be integrate into a toolkit, providing a native experience for users. This was used in GooFit to provide `GooFit::Application`, an class designed to make ROOT users feel at home.
4 4  
5   -# Custom namespace
  5 +## Custom namespace
6 6  
7 7 If you want to provide CLI11 in a custom namespace, you'll want to at least put `using CLI::App` in your namespace. You can also include Option, some errors, and validators. You can also put `using namespace CLI` inside your namespace to import everything.
8 8  
... ... @@ -17,14 +17,12 @@ You may also want to make your own copy of the `CLI11_PARSE` macro. Something li
17 17 }
18 18 ```
19 19  
20   -
21   -# Subclassing App
  20 +## Subclassing App
22 21  
23 22 If you subclass `App`, you'll just need to do a few things. You'll need a constructor; calling the base `App` constructor is a good idea, but not necessary (it just sets a description and adds a help flag.
24 23  
25 24 You can call anything you would like to configure in the constructor, like `option_defaults()->take_last()` or `fallthrough()`, and it will be set on all user instances. You can add flags and options, as well.
26 25  
27   -
28   -# Virtual functions provided
  26 +## Virtual functions provided
29 27  
30 28 You are given a few virtual functions that you can change (only on the main App). `pre_callback` runs right before the callbacks run, letting you print out custom messages at the top of your app.
... ...
book/chapters/validators.md
... ... @@ -49,7 +49,6 @@ The built-in validators for CLI11 are:
49 49 | `NonexistentPath` | Check for an non-existing path |
50 50 | `Range(min=0, max)` | Produce a range (factory). Min and max are inclusive. |
51 51  
52   -
53 52 And, the protected members that you can set when you make your own are:
54 53  
55 54 | Type | Member | Description |
... ...
docs/mainpage.md
... ... @@ -14,7 +14,6 @@ The main classes are:
14 14 |CLI::Timer | A timer class, only in CLI/Timer.hpp (not in `CLI11.hpp`) |
15 15 |CLI::AutoTimer | A timer that prints on deletion |
16 16  
17   -
18 17 Groups of related topics:
19 18  
20 19 | Name | Description |
... ...
scripts/mdlint_style.rb 0 → 100644
  1 +all
  2 +
  3 +exclude_rule 'MD013' # Line length
  4 +exclude_rule 'MD033' # Inline HTML
  5 +exclude_rule 'MD034' # Bare URL (for now)
  6 +
  7 +rule 'MD026', punctuation: '.,;:!' # Trailing punctuation in header (& in this case)
  8 +rule 'MD029', style: :ordered
... ...