1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-03 14:03:52 +00:00

fix: missing function definition (#793)

* the get_option_group definition was missing from the splitting of the calls.

* style: pre-commit.ci fixes

* the get_option_group definition was missing from the splitting of the calls.

* style: pre-commit.ci fixes

* add test for missing function

* style: pre-commit.ci fixes

* add test for get_option_group

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top 2022-10-28 06:57:54 -07:00 committed by GitHub
parent 4dbe4b4ec4
commit 25274e2c7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -433,6 +433,15 @@ CLI11_NODISCARD CLI11_INLINE CLI::App_p App::get_subcommand_ptr(int index) const
throw OptionNotFound(std::to_string(index)); 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 { CLI11_NODISCARD CLI11_INLINE std::size_t App::count_all() const {
std::size_t cnt{0}; std::size_t cnt{0};
for(const auto &opt : options_) { for(const auto &opt : options_) {

View File

@ -448,6 +448,12 @@ TEST_CASE_METHOD(ManyGroups, "SingleGroup", "[optiongroup]") {
CHECK_THROWS_AS(run(), CLI::RequiredError); 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]") { TEST_CASE_METHOD(ManyGroups, "ExcludesGroup", "[optiongroup]") {
// only 1 group can be used // only 1 group can be used
g1->excludes(g2); g1->excludes(g2);