diff --git a/.travis.yml b/.travis.yml index 8afb1350..1f31e470 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ matrix: .ci/build_docs.sh fi - # GCC 6 and Coverage + # GCC 7 and coverage (8 does not support lcov, wait till 9 and new lcov) - compiler: gcc env: - GCC_VER=7 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a110b2c..8bba8c04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,9 @@ Validators are now much more powerful [#118], all built in validators upgraded t Other changes: -* Dropped `set_*` names on options, using `type_name` and `type_size` instead of `set_custom_option`. Methods return this. +* Dropped `set_` on Option's `type_name`, `default_str`, and `default_val` +* Replaced `set_custom_option` with `type_name` and `type_size` instead of `set_custom_option`. Methods return `this`. +* Removed `set_` from App's `failure_message`, `footer`, `callback`, and `name` * Added `->each()` to make adding custom callbacks easier [#126] * Added filter argument to `get_subcommands`, `get_options`; use empty filter `{}` to avoid filtering * Added `get_groups()` to get groups diff --git a/README.md b/README.md index 5ba1372c..576b669c 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ subcommand name from matching. If an `App` (main or subcommand) has been parsed on the command line, `->parsed` will be true (or convert directly to bool). 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. -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 +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 even exit the program through the callback. The main `App` has a callback slot, as well, but it is generally not as useful. You are allowed to throw `CLI::Success` in the callbacks. 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 * `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details. * `.get_description()`: Access the description. * `.parsed()`: True if this subcommand was given on the command line. -* `.set_name(name)`: Add or change the name. -* `.set_callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. +* `.name(name)`: Add or change the name. +* `.callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. * `.allow_extras()`: Do not throw an error if extra arguments are left over. * `.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. -* `.set_footer(message)`: Set text to appear at the bottom of the help string. +* `.footer(message)`: Set text to appear at the bottom of the help string. * `.set_help_flag(name, message)`: Set the help flag name and message, returns a pointer to the created option. * `.set_help_all_flag(name, message)`: Set the help all flag name and message, returns a pointer to the created option. Expands subcommands. -* `.set_failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default). +* `.failure_message(func)`: Set the failure message function. Two provided: `CLI::FailureMessage::help` and `CLI::FailureMessage::simple` (the default). * `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand. > 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 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 but before run behavior, while -still giving the user freedom to `set_callback` on the main app. +still giving the user freedom to `callback` on the main app. The most important parse function is `parse(std::vector)`, 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. diff --git a/examples/subcom_in_files/subcommand_a.cpp b/examples/subcom_in_files/subcommand_a.cpp index e347148f..affc6e84 100644 --- a/examples/subcom_in_files/subcommand_a.cpp +++ b/examples/subcom_in_files/subcommand_a.cpp @@ -18,7 +18,7 @@ void setup_subcommand_a(CLI::App &app) { sub->add_flag("--with-foo", opt->with_foo, "Counter"); // Set the run function as callback to be called when this subcommand is issued. - sub->set_callback([opt]() { run_subcommand_a(*opt); }); + sub->callback([opt]() { run_subcommand_a(*opt); }); } /// The function that runs our code. diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 0c915c2b..d81ccfd6 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -222,13 +222,13 @@ class App { /// it is not possible to overload on std::function (fixed in c++14 /// and backported to c++11 on newer compilers). Use capture by reference /// to get a pointer to App if needed. - App *set_callback(std::function callback) { + App *callback(std::function callback) { callback_ = callback; return this; } /// Set a name for the app (empty will use parser to set the name) - App *set_name(std::string name = "") { + App *name(std::string name = "") { name_ = name; return this; } @@ -901,7 +901,7 @@ class App { } /// Provide a function to print a help message. The function gets access to the App pointer and error. - void set_failure_message(std::function function) { + void failure_message(std::function function) { failure_message_ = function; } @@ -1012,7 +1012,7 @@ class App { ///@{ /// Set footer. - App *set_footer(std::string footer) { + App *footer(std::string footer) { footer_ = footer; return this; } diff --git a/tests/CreationTest.cpp b/tests/CreationTest.cpp index 72c00bd3..e7c75f83 100644 --- a/tests/CreationTest.cpp +++ b/tests/CreationTest.cpp @@ -362,7 +362,7 @@ TEST_F(TApp, SubcommandDefaults) { app.prefix_command(); app.ignore_case(); app.fallthrough(); - app.set_footer("footy"); + app.footer("footy"); app.group("Stuff"); app.require_subcommand(2, 3); diff --git a/tests/HelpTest.cpp b/tests/HelpTest.cpp index e5cdb565..5f30f2ce 100644 --- a/tests/HelpTest.cpp +++ b/tests/HelpTest.cpp @@ -24,7 +24,7 @@ TEST(THelp, Basic) { TEST(THelp, Footer) { CLI::App app{"My prog"}; - app.set_footer("Report bugs to bugs@example.com"); + app.footer("Report bugs to bugs@example.com"); std::string help = app.help(); @@ -128,7 +128,7 @@ TEST(THelp, VectorOpts) { TEST(THelp, MultiPosOpts) { CLI::App app{"My prog"}; - app.set_name("program"); + app.name("program"); std::vector x, y; app.add_option("quick", x, "Disc")->expected(2); app.add_option("vals", y, "Other"); @@ -535,7 +535,7 @@ TEST_F(CapturedHelp, NormalError) { } TEST_F(CapturedHelp, RepacedError) { - app.set_failure_message(CLI::FailureMessage::help); + app.failure_message(CLI::FailureMessage::help); EXPECT_EQ(run(CLI::ExtrasError({"Thing"})), static_cast(CLI::ExitCodes::ExtrasError)); EXPECT_EQ(out.str(), ""); diff --git a/tests/SubcommandTest.cpp b/tests/SubcommandTest.cpp index 1a8174d9..ce8f658a 100644 --- a/tests/SubcommandTest.cpp +++ b/tests/SubcommandTest.cpp @@ -178,10 +178,10 @@ TEST_F(TApp, FooFooProblem) { TEST_F(TApp, Callbacks) { auto sub1 = app.add_subcommand("sub1"); - sub1->set_callback([]() { throw CLI::Success(); }); + sub1->callback([]() { throw CLI::Success(); }); auto sub2 = app.add_subcommand("sub2"); bool val = false; - sub2->set_callback([&val]() { val = true; }); + sub2->callback([&val]() { val = true; }); args = {"sub2"}; EXPECT_FALSE(val); @@ -191,9 +191,9 @@ TEST_F(TApp, Callbacks) { TEST_F(TApp, RuntimeErrorInCallback) { auto sub1 = app.add_subcommand("sub1"); - sub1->set_callback([]() { throw CLI::RuntimeError(); }); + sub1->callback([]() { throw CLI::RuntimeError(); }); auto sub2 = app.add_subcommand("sub2"); - sub2->set_callback([]() { throw CLI::RuntimeError(2); }); + sub2->callback([]() { throw CLI::RuntimeError(2); }); args = {"sub1"}; EXPECT_THROW(run(), CLI::RuntimeError); @@ -309,7 +309,7 @@ TEST_F(TApp, CallbackOrdering) { app.add_option("--val", val); auto sub = app.add_subcommand("sub"); - sub->set_callback([&val, &sub_val]() { sub_val = val; }); + sub->callback([&val, &sub_val]() { sub_val = val; }); args = {"sub", "--val=2"}; run(); @@ -573,7 +573,7 @@ TEST_F(SubcommandProgram, HelpOrder) { TEST_F(SubcommandProgram, Callbacks) { - start->set_callback([]() { throw CLI::Success(); }); + start->callback([]() { throw CLI::Success(); }); run(); @@ -668,8 +668,8 @@ TEST_F(SubcommandProgram, MixedOrderExtras) { TEST_F(SubcommandProgram, CallbackOrder) { std::vector callback_order; - start->set_callback([&callback_order]() { callback_order.push_back(1); }); - stop->set_callback([&callback_order]() { callback_order.push_back(2); }); + start->callback([&callback_order]() { callback_order.push_back(1); }); + stop->callback([&callback_order]() { callback_order.push_back(2); }); args = {"start", "stop"}; run();