Commit fff33502547884ccb79f9ca7d7ca3ef2ab7c2d2c
Committed by
GitHub
1 parent
c426c43b
fix issue with option defaults not propagating to option groups (#450)
Showing
2 changed files
with
13 additions
and
1 deletions
include/CLI/App.hpp
| @@ -993,7 +993,7 @@ class App { | @@ -993,7 +993,7 @@ class App { | ||
| 993 | /// creates an option group as part of the given app | 993 | /// creates an option group as part of the given app |
| 994 | template <typename T = Option_group> | 994 | template <typename T = Option_group> |
| 995 | T *add_option_group(std::string group_name, std::string group_description = "") { | 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 | auto ptr = option_group.get(); | 997 | auto ptr = option_group.get(); |
| 998 | // move to App_p for overload resolution on older gcc versions | 998 | // move to App_p for overload resolution on older gcc versions |
| 999 | App_p app_ptr = std::dynamic_pointer_cast<App>(option_group); | 999 | App_p app_ptr = std::dynamic_pointer_cast<App>(option_group); |
tests/OptionGroupTest.cpp
| @@ -374,6 +374,18 @@ TEST_F(TApp, InvalidOptions) { | @@ -374,6 +374,18 @@ TEST_F(TApp, InvalidOptions) { | ||
| 374 | EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound); | 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 | struct ManyGroups : public TApp { | 389 | struct ManyGroups : public TApp { |
| 378 | 390 | ||
| 379 | CLI::Option_group *main{nullptr}; | 391 | CLI::Option_group *main{nullptr}; |