1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

Adding remaining, only works on master app for now

This commit is contained in:
Henry Fredrick Schreiner 2017-11-16 10:57:35 -05:00 committed by Henry Schreiner
parent ebd238a9db
commit fc35014dad
2 changed files with 35 additions and 0 deletions

View File

@ -863,6 +863,15 @@ class App {
/// This gets a vector of pointers with the original parse order /// This gets a vector of pointers with the original parse order
const std::vector<Option *> &parse_order() const { return parse_order_; } const std::vector<Option *> &parse_order() const { return parse_order_; }
/// This retuns the missing options from the current subcommand
std::vector<std::string> remaining() const {
std::vector<std::string> miss_list;
for(const std::pair<detail::Classifer, std::string>& miss : missing_) {
miss_list.push_back(std::get<1>(miss));
}
return miss_list;
}
///@} ///@}
protected: protected:

View File

@ -281,6 +281,32 @@ TEST_F(TApp, RequiredSubCom) {
run(); run();
} }
TEST_F(TApp, SubComExtras) {
app.allow_extras();
auto sub = app.add_subcommand("sub");
args = {"extra", "sub"};
run();
EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra"}));
EXPECT_EQ(sub->remaining(), std::vector<std::string>());
app.reset();
args = {"extra1", "extra2", "sub"};
run();
EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"}));
EXPECT_EQ(sub->remaining(), std::vector<std::string>());
app.reset();
//args = {"sub", "extra"};
//run();
//EXPECT_EQ(app.remaining(), std::vector<std::string>());
//EXPECT_EQ(sub->remaining(), std::vector<std::string>({"extra"}));
}
TEST_F(TApp, Required1SubCom) { TEST_F(TApp, Required1SubCom) {
app.require_subcommand(1); app.require_subcommand(1);
app.add_subcommand("sub1"); app.add_subcommand("sub1");