Commit 25274e2c7b07d69534e9688a5956ff48f91eab5e

Authored by Philip Top
Committed by GitHub
1 parent 4dbe4b4e

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>
include/CLI/impl/App_inl.hpp
... ... @@ -433,6 +433,15 @@ CLI11_NODISCARD CLI11_INLINE CLI::App_p App::get_subcommand_ptr(int index) const
433 433 throw OptionNotFound(std::to_string(index));
434 434 }
435 435  
  436 +CLI11_NODISCARD CLI11_INLINE CLI::App *App::get_option_group(std::string group_name) const {
  437 + for(const App_p &app : subcommands_) {
  438 + if(app->name_.empty() && app->group_ == group_name) {
  439 + return app.get();
  440 + }
  441 + }
  442 + throw OptionNotFound(group_name);
  443 +}
  444 +
436 445 CLI11_NODISCARD CLI11_INLINE std::size_t App::count_all() const {
437 446 std::size_t cnt{0};
438 447 for(const auto &opt : options_) {
... ...
tests/OptionGroupTest.cpp
... ... @@ -448,6 +448,12 @@ TEST_CASE_METHOD(ManyGroups, &quot;SingleGroup&quot;, &quot;[optiongroup]&quot;) {
448 448 CHECK_THROWS_AS(run(), CLI::RequiredError);
449 449 }
450 450  
  451 +TEST_CASE_METHOD(ManyGroups, "getGroup", "[optiongroup]") {
  452 + auto *mn = app.get_option_group("main");
  453 + CHECK(mn == main);
  454 + CHECK_THROWS_AS(app.get_option_group("notfound"), CLI::OptionNotFound);
  455 +}
  456 +
451 457 TEST_CASE_METHOD(ManyGroups, "ExcludesGroup", "[optiongroup]") {
452 458 // only 1 group can be used
453 459 g1->excludes(g2);
... ...