1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-02 13:43:52 +00:00

Adding testing for required subcommands

This commit is contained in:
Henry Fredrick Schreiner 2017-02-20 09:29:20 -05:00
parent 2ddc7d4346
commit 537aa3aa5d
4 changed files with 31 additions and 3 deletions

View File

@ -1,9 +1,9 @@
## Version 0.5 (in progress)
* Added `require_subcommand` to `App`, to simplify forcing subcommands. Do not "chain" with `add_subcommand`, since that is the subcommand, not the master `App`. 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`.
* Added printout of ini file text given parsed options, skips flags.
* Support for quotes and spaces in ini files
* Support for Windows (added Appveyor) (Still use `--` syntax)
* Fixes to allow support for Windows (added Appveyor) (Use `-`, not `/` syntax)
## Version 0.4

View File

@ -43,6 +43,7 @@ This library was built to supply the Application object for the GooFit CUDA/OMP
* Evaluate compatibility with [ROOT](https://root.cern.ch)'s TApplication object.
* Add way for subclasses to return remaining options rather than throwing error
* Chained subcommands are not supported, 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.
* Support case insensitive set and/or subcommands?
See the [changelog](./CHANGELOG.md) or [GitHub releases](https://github.com/henryiii/CLI11/releases) for details.

View File

@ -104,3 +104,18 @@ TEST(THelp, Excludes) {
EXPECT_THAT(help, HasSubstr("Excludes: --op1"));
}
TEST(THelp, Subcom) {
CLI::App app{"My prog"};
app.add_subcommand("sub1");
app.add_subcommand("sub2");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [SUBCOMMAND]"));
app.require_subcommand();
help = app.help();
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] SUBCOMMAND"));
}

View File

@ -40,9 +40,21 @@ TEST_F(TApp, Callbacks) {
}
// TODO: Add directory test
TEST_F(TApp, RequiredSubCom) {
auto sub1 = app.add_subcommand("sub1");
auto sub2 = app.add_subcommand("sub2");
app.require_subcommand();
EXPECT_THROW(run(), CLI::RequiredError);
app.reset();
args = {"sub1"};
EXPECT_NO_THROW(run());
}
struct SubcommandProgram : public TApp {