Commit b2e471ac4d6a24922d848e573e9cbbd08cc5f3ca

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

Removing set_ for failure_message, footer, name, and callback

.travis.yml
... ... @@ -56,7 +56,7 @@ matrix:
56 56 .ci/build_docs.sh
57 57 fi
58 58  
59   - # GCC 6 and Coverage
  59 + # GCC 7 and coverage (8 does not support lcov, wait till 9 and new lcov)
60 60 - compiler: gcc
61 61 env:
62 62 - GCC_VER=7
... ...
CHANGELOG.md
... ... @@ -36,7 +36,9 @@ Validators are now much more powerful [#118], all built in validators upgraded t
36 36  
37 37 Other changes:
38 38  
39   -* Dropped `set_*` names on options, using `type_name` and `type_size` instead of `set_custom_option`. Methods return this.
  39 +* Dropped `set_` on Option's `type_name`, `default_str`, and `default_val`
  40 +* Replaced `set_custom_option` with `type_name` and `type_size` instead of `set_custom_option`. Methods return `this`.
  41 +* Removed `set_` from App's `failure_message`, `footer`, `callback`, and `name`
40 42 * Added `->each()` to make adding custom callbacks easier [#126]
41 43 * Added filter argument to `get_subcommands`, `get_options`; use empty filter `{}` to avoid filtering
42 44 * Added `get_groups()` to get groups
... ...
README.md
... ... @@ -232,7 +232,7 @@ subcommand name from matching.
232 232 If an `App` (main or subcommand) has been parsed on the command line, `->parsed` will be true (or convert directly to bool).
233 233 All `App`s have a `get_subcommands()` method, which returns a list of pointers to the subcommands passed on the command line. A `got_subcommand(App_or_name)` method is also provided that will check to see if an `App` pointer or a string name was collected on the command line.
234 234  
235   -For many cases, however, using an app's callback may be easier. Every app executes a callback function after it parses; just use a lambda function (with capture to get parsed values) to `.set_callback`. If you throw `CLI::Success` or `CLI::RuntimeError(return_value)`, you can
  235 +For many cases, however, using an app's callback may be easier. Every app executes a callback function after it parses; just use a lambda function (with capture to get parsed values) to `.callback`. If you throw `CLI::Success` or `CLI::RuntimeError(return_value)`, you can
236 236 even exit the program through the callback. The main `App` has a callback slot, as well, but it is generally not as useful.
237 237 You are allowed to throw `CLI::Success` in the callbacks.
238 238 Multiple subcommands are allowed, to allow [`Click`][Click] like series of commands (order is preserved).
... ... @@ -254,14 +254,14 @@ There are several options that are supported on the main app and subcommands. Th
254 254 * `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details.
255 255 * `.get_description()`: Access the description.
256 256 * `.parsed()`: True if this subcommand was given on the command line.
257   -* `.set_name(name)`: Add or change the name.
258   -* `.set_callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point.
  257 +* `.name(name)`: Add or change the name.
  258 +* `.callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point.
259 259 * `.allow_extras()`: Do not throw an error if extra arguments are left over.
260 260 * `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognised item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app.
261   -* `.set_footer(message)`: Set text to appear at the bottom of the help string.
  261 +* `.footer(message)`: Set text to appear at the bottom of the help string.
262 262 * `.set_help_flag(name, message)`: Set the help flag name and message, returns a pointer to the created option.
263 263 * `.set_help_all_flag(name, message)`: Set the help all flag name and message, returns a pointer to the created option. Expands subcommands.
264   -* `.set_failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default).
  264 +* `.failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default).
265 265 * `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand.
266 266  
267 267 > Note: if you have a fixed number of required positional options, that will match before subcommand names. `{}` is an empty filter function.
... ... @@ -320,7 +320,7 @@ their own formatter since you can't access anything but the call operator once a
320 320  
321 321 The App class was designed allow toolkits to subclass it, to provide preset default options (see above) and setup/teardown code. Subcommands remain an unsubclassed `App`, since those are not expected to need setup and teardown. The default `App` only adds a help flag, `-h,--help`, than can removed/replaced using `.set_help_flag(name, help_string)`. You can also set a help-all flag with `.set_help_all_flag(name, help_string)`; this will expand the subcommands (one level only). You can remove options if you have pointers to them using `.remove_option(opt)`. You can add a `pre_callback` override to customize the after parse
322 322 but before run behavior, while
323   -still giving the user freedom to `set_callback` on the main app.
  323 +still giving the user freedom to `callback` on the main app.
324 324  
325 325 The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector.
326 326  
... ...
examples/subcom_in_files/subcommand_a.cpp
... ... @@ -18,7 +18,7 @@ void setup_subcommand_a(CLI::App &amp;app) {
18 18 sub->add_flag("--with-foo", opt->with_foo, "Counter");
19 19  
20 20 // Set the run function as callback to be called when this subcommand is issued.
21   - sub->set_callback([opt]() { run_subcommand_a(*opt); });
  21 + sub->callback([opt]() { run_subcommand_a(*opt); });
22 22 }
23 23  
24 24 /// The function that runs our code.
... ...
include/CLI/App.hpp
... ... @@ -222,13 +222,13 @@ class App {
222 222 /// it is not possible to overload on std::function (fixed in c++14
223 223 /// and backported to c++11 on newer compilers). Use capture by reference
224 224 /// to get a pointer to App if needed.
225   - App *set_callback(std::function<void()> callback) {
  225 + App *callback(std::function<void()> callback) {
226 226 callback_ = callback;
227 227 return this;
228 228 }
229 229  
230 230 /// Set a name for the app (empty will use parser to set the name)
231   - App *set_name(std::string name = "") {
  231 + App *name(std::string name = "") {
232 232 name_ = name;
233 233 return this;
234 234 }
... ... @@ -901,7 +901,7 @@ class App {
901 901 }
902 902  
903 903 /// Provide a function to print a help message. The function gets access to the App pointer and error.
904   - void set_failure_message(std::function<std::string(const App *, const Error &e)> function) {
  904 + void failure_message(std::function<std::string(const App *, const Error &e)> function) {
905 905 failure_message_ = function;
906 906 }
907 907  
... ... @@ -1012,7 +1012,7 @@ class App {
1012 1012 ///@{
1013 1013  
1014 1014 /// Set footer.
1015   - App *set_footer(std::string footer) {
  1015 + App *footer(std::string footer) {
1016 1016 footer_ = footer;
1017 1017 return this;
1018 1018 }
... ...
tests/CreationTest.cpp
... ... @@ -362,7 +362,7 @@ TEST_F(TApp, SubcommandDefaults) {
362 362 app.prefix_command();
363 363 app.ignore_case();
364 364 app.fallthrough();
365   - app.set_footer("footy");
  365 + app.footer("footy");
366 366 app.group("Stuff");
367 367 app.require_subcommand(2, 3);
368 368  
... ...
tests/HelpTest.cpp
... ... @@ -24,7 +24,7 @@ TEST(THelp, Basic) {
24 24  
25 25 TEST(THelp, Footer) {
26 26 CLI::App app{"My prog"};
27   - app.set_footer("Report bugs to bugs@example.com");
  27 + app.footer("Report bugs to bugs@example.com");
28 28  
29 29 std::string help = app.help();
30 30  
... ... @@ -128,7 +128,7 @@ TEST(THelp, VectorOpts) {
128 128  
129 129 TEST(THelp, MultiPosOpts) {
130 130 CLI::App app{"My prog"};
131   - app.set_name("program");
  131 + app.name("program");
132 132 std::vector<int> x, y;
133 133 app.add_option("quick", x, "Disc")->expected(2);
134 134 app.add_option("vals", y, "Other");
... ... @@ -535,7 +535,7 @@ TEST_F(CapturedHelp, NormalError) {
535 535 }
536 536  
537 537 TEST_F(CapturedHelp, RepacedError) {
538   - app.set_failure_message(CLI::FailureMessage::help);
  538 + app.failure_message(CLI::FailureMessage::help);
539 539  
540 540 EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast<int>(CLI::ExitCodes::ExtrasError));
541 541 EXPECT_EQ(out.str(), "");
... ...
tests/SubcommandTest.cpp
... ... @@ -178,10 +178,10 @@ TEST_F(TApp, FooFooProblem) {
178 178  
179 179 TEST_F(TApp, Callbacks) {
180 180 auto sub1 = app.add_subcommand("sub1");
181   - sub1->set_callback([]() { throw CLI::Success(); });
  181 + sub1->callback([]() { throw CLI::Success(); });
182 182 auto sub2 = app.add_subcommand("sub2");
183 183 bool val = false;
184   - sub2->set_callback([&val]() { val = true; });
  184 + sub2->callback([&val]() { val = true; });
185 185  
186 186 args = {"sub2"};
187 187 EXPECT_FALSE(val);
... ... @@ -191,9 +191,9 @@ TEST_F(TApp, Callbacks) {
191 191  
192 192 TEST_F(TApp, RuntimeErrorInCallback) {
193 193 auto sub1 = app.add_subcommand("sub1");
194   - sub1->set_callback([]() { throw CLI::RuntimeError(); });
  194 + sub1->callback([]() { throw CLI::RuntimeError(); });
195 195 auto sub2 = app.add_subcommand("sub2");
196   - sub2->set_callback([]() { throw CLI::RuntimeError(2); });
  196 + sub2->callback([]() { throw CLI::RuntimeError(2); });
197 197  
198 198 args = {"sub1"};
199 199 EXPECT_THROW(run(), CLI::RuntimeError);
... ... @@ -309,7 +309,7 @@ TEST_F(TApp, CallbackOrdering) {
309 309 app.add_option("--val", val);
310 310  
311 311 auto sub = app.add_subcommand("sub");
312   - sub->set_callback([&val, &sub_val]() { sub_val = val; });
  312 + sub->callback([&val, &sub_val]() { sub_val = val; });
313 313  
314 314 args = {"sub", "--val=2"};
315 315 run();
... ... @@ -573,7 +573,7 @@ TEST_F(SubcommandProgram, HelpOrder) {
573 573  
574 574 TEST_F(SubcommandProgram, Callbacks) {
575 575  
576   - start->set_callback([]() { throw CLI::Success(); });
  576 + start->callback([]() { throw CLI::Success(); });
577 577  
578 578 run();
579 579  
... ... @@ -668,8 +668,8 @@ TEST_F(SubcommandProgram, MixedOrderExtras) {
668 668  
669 669 TEST_F(SubcommandProgram, CallbackOrder) {
670 670 std::vector<int> callback_order;
671   - start->set_callback([&callback_order]() { callback_order.push_back(1); });
672   - stop->set_callback([&callback_order]() { callback_order.push_back(2); });
  671 + start->callback([&callback_order]() { callback_order.push_back(1); });
  672 + stop->callback([&callback_order]() { callback_order.push_back(2); });
673 673  
674 674 args = {"start", "stop"};
675 675 run();
... ...