Commit fc35014dad86a528f25a2105476938a220a3fd40

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent ebd238a9

Adding remaining, only works on master app for now

include/CLI/App.hpp
... ... @@ -863,6 +863,15 @@ class App {
863 863 /// This gets a vector of pointers with the original parse order
864 864 const std::vector<Option *> &parse_order() const { return parse_order_; }
865 865  
  866 + /// This retuns the missing options from the current subcommand
  867 + std::vector<std::string> remaining() const {
  868 + std::vector<std::string> miss_list;
  869 + for(const std::pair<detail::Classifer, std::string>& miss : missing_) {
  870 + miss_list.push_back(std::get<1>(miss));
  871 + }
  872 + return miss_list;
  873 + }
  874 +
866 875 ///@}
867 876  
868 877 protected:
... ...
tests/SubcommandTest.cpp
... ... @@ -281,6 +281,32 @@ TEST_F(TApp, RequiredSubCom) {
281 281 run();
282 282 }
283 283  
  284 +TEST_F(TApp, SubComExtras) {
  285 + app.allow_extras();
  286 + auto sub = app.add_subcommand("sub");
  287 +
  288 + args = {"extra", "sub"};
  289 + run();
  290 + EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra"}));
  291 + EXPECT_EQ(sub->remaining(), std::vector<std::string>());
  292 +
  293 + app.reset();
  294 +
  295 + args = {"extra1", "extra2", "sub"};
  296 + run();
  297 + EXPECT_EQ(app.remaining(), std::vector<std::string>({"extra1", "extra2"}));
  298 + EXPECT_EQ(sub->remaining(), std::vector<std::string>());
  299 +
  300 + app.reset();
  301 +
  302 + //args = {"sub", "extra"};
  303 + //run();
  304 + //EXPECT_EQ(app.remaining(), std::vector<std::string>());
  305 + //EXPECT_EQ(sub->remaining(), std::vector<std::string>({"extra"}));
  306 +
  307 +
  308 +}
  309 +
284 310 TEST_F(TApp, Required1SubCom) {
285 311 app.require_subcommand(1);
286 312 app.add_subcommand("sub1");
... ...