Commit fff33502547884ccb79f9ca7d7ca3ef2ab7c2d2c

Authored by Philip Top
Committed by GitHub
1 parent c426c43b

fix issue with option defaults not propagating to option groups (#450)

include/CLI/App.hpp
... ... @@ -993,7 +993,7 @@ class App {
993 993 /// creates an option group as part of the given app
994 994 template <typename T = Option_group>
995 995 T *add_option_group(std::string group_name, std::string group_description = "") {
996   - auto option_group = std::make_shared<T>(std::move(group_description), group_name, nullptr);
  996 + auto option_group = std::make_shared<T>(std::move(group_description), group_name, this);
997 997 auto ptr = option_group.get();
998 998 // move to App_p for overload resolution on older gcc versions
999 999 App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
... ...
tests/OptionGroupTest.cpp
... ... @@ -374,6 +374,18 @@ TEST_F(TApp, InvalidOptions) {
374 374 EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound);
375 375 }
376 376  
  377 +TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
  378 + app.option_defaults()->ignore_case();
  379 + auto ogroup = app.add_option_group("clusters");
  380 + int res{0};
  381 + ogroup->add_option("--test1", res);
  382 +
  383 + args = {"--Test1", "5"};
  384 + run();
  385 + EXPECT_EQ(res, 5);
  386 + EXPECT_EQ(app.count_all(), 1u);
  387 +}
  388 +
377 389 struct ManyGroups : public TApp {
378 390  
379 391 CLI::Option_group *main{nullptr};
... ...