mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-02 05:33:53 +00:00
Adding test for extras access
This commit is contained in:
parent
cfc389d4e4
commit
e328364ae7
@ -1,9 +1,9 @@
|
|||||||
## Version 0.5 (in progress)
|
## Version 0.5 (in progress)
|
||||||
|
|
||||||
* `->ignore_case()` added to subcommands, options, and `add_set_ignore_case`. Subcommand inherit setting from parent App on creation.
|
* `->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)
|
* 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. (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.
|
||||||
* Added `require_subcommand` to `App`, to simplify forcing subcommands. Do not "chain" with `add_subcommand`, since that is the subcommand, not the master `App`.
|
* 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.
|
* Added printout of ini file text given parsed options, skips flags.
|
||||||
* Support for quotes and spaces in ini files
|
* Support for quotes and spaces in ini files
|
||||||
* Fixes to allow support for Windows (added Appveyor) (Use `-`, not `/` syntax)
|
* Fixes to allow support for Windows (added Appveyor) (Use `-`, not `/` syntax)
|
||||||
|
@ -41,8 +41,6 @@ This library was built to supply the Application object for the GooFit CUDA/OMP
|
|||||||
* Collect user feedback
|
* Collect user feedback
|
||||||
* Ini configuration support is basic (long options only, no vector support), is more needed?
|
* 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.
|
* 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
|
* 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.
|
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
|
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.
|
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
|
## Subclassing
|
||||||
|
|
||||||
|
@ -599,3 +599,35 @@ TEST_F(TApp, RangeDouble) {
|
|||||||
EXPECT_NO_THROW(run());
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -15,10 +15,10 @@ struct TApp : public ::testing::Test {
|
|||||||
CLI::App app{"My Test Program"};
|
CLI::App app{"My Test Program"};
|
||||||
input_t args;
|
input_t args;
|
||||||
|
|
||||||
void run() {
|
std::vector<std::string> run() {
|
||||||
input_t newargs = args;
|
input_t newargs = args;
|
||||||
std::reverse(std::begin(newargs), std::end(newargs));
|
std::reverse(std::begin(newargs), std::end(newargs));
|
||||||
app.parse(newargs);
|
return app.parse(newargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user