Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing function definition #793

Merged
merged 9 commits into from
Oct 28, 2022
9 changes: 9 additions & 0 deletions include/CLI/impl/App_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ CLI11_NODISCARD CLI11_INLINE CLI::App_p App::get_subcommand_ptr(int index) const
throw OptionNotFound(std::to_string(index));
}

CLI11_NODISCARD CLI11_INLINE CLI::App *App::get_option_group(std::string group_name) const {
for(const App_p &app : subcommands_) {
if(app->name_.empty() && app->group_ == group_name) {
return app.get();
}
}
throw OptionNotFound(group_name);
}

CLI11_NODISCARD CLI11_INLINE std::size_t App::count_all() const {
std::size_t cnt{0};
for(const auto &opt : options_) {
Expand Down
6 changes: 6 additions & 0 deletions tests/OptionGroupTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ TEST_CASE_METHOD(ManyGroups, "SingleGroup", "[optiongroup]") {
CHECK_THROWS_AS(run(), CLI::RequiredError);
}

TEST_CASE_METHOD(ManyGroups, "getGroup", "[optiongroup]") {
auto *mn = app.get_option_group("main");
CHECK(mn == main);
CHECK_THROWS_AS(app.get_option_group("notfound"), CLI::OptionNotFound);
}

TEST_CASE_METHOD(ManyGroups, "ExcludesGroup", "[optiongroup]") {
// only 1 group can be used
g1->excludes(g2);
Expand Down