Commit 9943c0300fc0cf92c8c5cf1787a252ed06e0a49e

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent b453aeba

Adding bits of touchup, one new example for validators

CHANGELOG.md
... ... @@ -15,6 +15,8 @@ Changes to the help system (most normal users will not notice this):
15 15 * Removed `help_*` functions.
16 16 * Protected function `_has_help_positional` removed.
17 17 * `format_help` can now be chained.
  18 +* Added getters for the missing parts of options (help no longer uses any private parts).
  19 +* Help flags now use new `short_circuit` property to simplify parsing. [#121]
18 20  
19 21  
20 22 New for Config file reading and writing [#121]:
... ... @@ -38,7 +40,6 @@ Validators are now much more powerful [#118], all built in validators upgraded t
38 40 Other changes:
39 41  
40 42 * Fixing `parse(args)`'s `args` setting and ordering after parse. [#141]
41   -* Cleaner tests without `app.reset()` (and `reset` is now `clear`). [#141]
42 43 * Replaced `set_custom_option` with `type_name` and `type_size` instead of `set_custom_option`. Methods return `this`. [#136]
43 44 * Dropped `set_` on Option's `type_name`, `default_str`, and `default_val`. [#136]
44 45 * Removed `set_` from App's `failure_message`, `footer`, `callback`, and `name`. [#136]
... ... @@ -46,18 +47,20 @@ Other changes:
46 47 * Added `->each()` to make adding custom callbacks easier. [#126]
47 48 * Added filter argument to `get_subcommands`, `get_options`; use empty filter `{}` to avoid filtering.
48 49 * Added `get_groups()` to get groups.
49   -* Added getters for the missing parts of options (help no longer uses any private parts).
50 50 * Better support for manual options with `get_option`, `set_results`, and `empty`. [#119]
51 51 * `lname` and `sname` have getters, added `const get_parent`. [#120]
52 52 * Using `add_set` will now capture L-values for sets, allowing further modification. [#113]
53   -* Internally, `type_name` is now a lambda function; for sets, this reads the set live. [#116]
54 53 * Dropped duplicate way to run `get_type_name` (`get_typeval`).
55   -* Testing (only) now uses submodules. [#111]
56 54 * Removed `requires` in favor of `needs` (deprecated in last version). [#112]
  55 +* Const added to argv. [#126]
  56 +
  57 +Backend and testing changes:
  58 +
  59 +* Internally, `type_name` is now a lambda function; for sets, this reads the set live. [#116]
  60 +* Cleaner tests without `app.reset()` (and `reset` is now `clear`). [#141]
57 61 * Better CMake policy handling. [#110]
58 62 * Includes are properly sorted. [#120]
59   -* Help flags now use new `short_circuit` property to simplify parsing. [#121]
60   -* Const added to argv. [#126]
  63 +* Testing (only) now uses submodules. [#111]
61 64  
62 65 [#109]: https://github.com/CLIUtils/CLI11/pull/109
63 66 [#110]: https://github.com/CLIUtils/CLI11/pull/110
... ...
examples/CMakeLists.txt
... ... @@ -60,6 +60,20 @@ set_property(TEST subcommands_all PROPERTY PASS_REGULAR_EXPRESSION
60 60 "Subcommand: start"
61 61 "Subcommand: stop")
62 62  
  63 +add_cli_exe(validators validators.cpp)
  64 +add_test(NAME validators_help COMMAND validators --help)
  65 +set_property(TEST validators_help PROPERTY PASS_REGULAR_EXPRESSION
  66 + " -f,--file FILE File name"
  67 + " -v,--value INT in [3 - 6] Value in range")
  68 +add_test(NAME validators_file COMMAND validators --file nonex.xxx)
  69 +set_property(TEST validators_file PROPERTY PASS_REGULAR_EXPRESSION
  70 + "--file: File does not exist: nonex.xxx"
  71 + "Run with --help for more information.")
  72 +add_test(NAME validators_plain COMMAND validators --value 9)
  73 +set_property(TEST validators_plain PROPERTY PASS_REGULAR_EXPRESSION
  74 + "--value: Value 9 not in range 3 to 6"
  75 + "Run with --help for more information.")
  76 +
63 77 add_cli_exe(groups groups.cpp)
64 78 add_test(NAME groups_none COMMAND groups)
65 79 set_property(TEST groups_none PROPERTY PASS_REGULAR_EXPRESSION
... ...
examples/validators.cpp 0 → 100644
  1 +#include "CLI/CLI.hpp"
  2 +
  3 +int main(int argc, char **argv) {
  4 +
  5 + CLI::App app("Validator checker");
  6 +
  7 + std::string file;
  8 + app.add_option("-f,--file,file", file, "File name")->check(CLI::ExistingFile);
  9 +
  10 + int count;
  11 + app.add_option("-v,--value", count, "Value in range")->check(CLI::Range(3, 6));
  12 + CLI11_PARSE(app, argc, argv);
  13 +
  14 + std::cout << "Try printing help or failing the validator" << std::endl;
  15 +
  16 + return 0;
  17 +}
... ...