1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 21:23:52 +00:00

Adding test for extras access

This commit is contained in:
Henry Fredrick Schreiner 2017-02-20 14:08:12 -05:00
parent cfc389d4e4
commit e328364ae7
4 changed files with 38 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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<std::string> left_over;
EXPECT_NO_THROW({left_over = run();});
EXPECT_TRUE(val);
EXPECT_EQ(std::vector<std::string>({"-x"}), left_over);
}
TEST_F(TApp, AllowExtrasOrder) {
app.allow_extras();
args = {"-x", "-f"};
std::vector<std::string> left_over;
EXPECT_NO_THROW({left_over = run();});
EXPECT_EQ(std::vector<std::string>({"-f", "-x"}), left_over);
app.reset();
std::vector<std::string> left_over_2;
left_over_2 = app.parse(left_over);
EXPECT_EQ(left_over, left_over_2);
}

View File

@ -15,10 +15,10 @@ struct TApp : public ::testing::Test {
CLI::App app{"My Test Program"};
input_t args;
void run() {
std::vector<std::string> run() {
input_t newargs = args;
std::reverse(std::begin(newargs), std::end(newargs));
app.parse(newargs);
return app.parse(newargs);
}
};