1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 04:33:53 +00:00

Throw error if subcommand does not exist, better test

This commit is contained in:
Henry Fredrick Schreiner 2017-03-15 09:22:45 -04:00
parent c5cdace048
commit dbe03bea95
2 changed files with 13 additions and 1 deletions

View File

@ -540,7 +540,10 @@ public:
for(const auto subcomptr : selected_subcommands_)
if(subcomptr->check_name(name))
return true;
for(const App_p &subcomptr : subcommands_)
if(subcomptr->check_name(name))
return false;
throw CLI::OptionNotFound(name);
}
///@}

View File

@ -50,6 +50,15 @@ TEST_F(TApp, MultiSubFallthrough) {
app.require_subcommand(1);
EXPECT_THROW(run(), CLI::RequiredError);
app.reset();
args = {"sub1"};
run();
EXPECT_TRUE(app.got_subcommand("sub1"));
EXPECT_FALSE(app.got_subcommand("sub2"));
EXPECT_THROW(app.got_subcommand("sub3"), CLI::OptionNotFound);
}