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:
parent
c5cdace048
commit
dbe03bea95
@ -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);
|
||||
}
|
||||
|
||||
///@}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user