diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe639e3..85c29b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ ## Version 0.5 (in progress) * `->ignore_case()` added to subcommands, options, and `add_set_ignore_case`. Subcommand inherit setting from parent App on creation. -* Subcommands now can be "chained", that is, left over arguments can now include subcommands that then get parsed. Subcommands are now a list (`get_subcommands`). Added `got_subcommand(App_or_name)` to check for subcommands. (untested) -* Added `.allow_extras()` to disable error on failure. Parse returns a vector of leftover options. Renamed error to `ExtrasError`, and now triggers on extra options too. (untested) -* Added `require_subcommand` to `App`, to simplify forcing subcommands. Do not "chain" with `add_subcommand`, since that is the subcommand, not the master `App`. +* Subcommands now can be "chained", that is, left over arguments can now include subcommands that then get parsed. Subcommands are now a list (`get_subcommands`). Added `got_subcommand(App_or_name)` to check for subcommands. +* Added `.allow_extras()` to disable error on failure. Parse returns a vector of leftover options. Renamed error to `ExtrasError`, and now triggers on extra options too. +* Added `require_subcommand` to `App`, to simplify forcing subcommands. Do **not** do `add_subcommand()->require_subcommand`, since that is the subcommand, not the master `App`. * Added printout of ini file text given parsed options, skips flags. * Support for quotes and spaces in ini files * Fixes to allow support for Windows (added Appveyor) (Use `-`, not `/` syntax) diff --git a/README.md b/README.md index 7a6d2966..e1ee44f8 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,6 @@ This library was built to supply the Application object for the GooFit CUDA/OMP * Collect user feedback * Ini configuration support is basic (long options only, no vector support), is more needed? * Evaluate compatibility with [ROOT](https://root.cern.ch)'s TApplication object. - * Add tests: Add way for subclasses to return remaining options rather than throwing error -* Chained subcommands are not tested, once a subcommand is given the rest of the options go to that subcommand, rather than allowing multiple subcommands. This is currently intentional behavior, but multiple base level subcommands, like [`Click`](http://click.pocoo.org) supports, might be considered in the future. * Throw error if `ignore_case` causes non-unique matches See the [changelog](./CHANGELOG.md) or [GitHub releases](https://github.com/henryiii/CLI11/releases) for details. @@ -164,7 +162,7 @@ Subcommands are naturally supported, with an infinite depth. To add a subcommand All `App`s have a `get_subcommands()` method, which returns a list of pointers to the subcommand passed on the command line. A simple compare of these pointers to each subcommand allows choosing based on subcommand, facilitated by a `got_subcommand(App_or_name) method that will check the list for you. 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 `.add_callback`. If you throw `CLI::Success`, 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. - +Multiple subcommands are allowed, to allow [`Click`](http://click.pocoo.org) like series of commands (order is preserved). If you want only one, throw `CLI::Success` or only process one. ## Subclassing diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index cc0194b8..643b6ba2 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -599,3 +599,35 @@ TEST_F(TApp, RangeDouble) { EXPECT_NO_THROW(run()); } +// Check to make sure progromatic access to left over is available +TEST_F(TApp, AllowExtras) { + + app.allow_extras(); + + bool val = true; + app.add_flag("-f", val); + EXPECT_FALSE(val); + + args = {"-x", "-f"}; + std::vector left_over; + EXPECT_NO_THROW({left_over = run();}); + EXPECT_TRUE(val); + EXPECT_EQ(std::vector({"-x"}), left_over); + +} + +TEST_F(TApp, AllowExtrasOrder) { + + app.allow_extras(); + + args = {"-x", "-f"}; + std::vector left_over; + EXPECT_NO_THROW({left_over = run();}); + EXPECT_EQ(std::vector({"-f", "-x"}), left_over); + app.reset(); + + std::vector left_over_2; + left_over_2 = app.parse(left_over); + EXPECT_EQ(left_over, left_over_2); + +} diff --git a/tests/app_helper.hpp b/tests/app_helper.hpp index c06739e8..3e265bfb 100644 --- a/tests/app_helper.hpp +++ b/tests/app_helper.hpp @@ -15,10 +15,10 @@ struct TApp : public ::testing::Test { CLI::App app{"My Test Program"}; input_t args; - void run() { + std::vector run() { input_t newargs = args; std::reverse(std::begin(newargs), std::end(newargs)); - app.parse(newargs); + return app.parse(newargs); } };