Skip to content

Commit

Permalink
fix issue with option defaults not propagating to option groups (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp authored and henryiii committed Jun 2, 2020
1 parent eb1150d commit 6f589b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ class App {
/// creates an option group as part of the given app
template <typename T = Option_group>
T *add_option_group(std::string group_name, std::string group_description = "") {
auto option_group = std::make_shared<T>(std::move(group_description), group_name, nullptr);
auto option_group = std::make_shared<T>(std::move(group_description), group_name, this);
auto ptr = option_group.get();
// move to App_p for overload resolution on older gcc versions
App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
Expand Down
12 changes: 12 additions & 0 deletions tests/OptionGroupTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ TEST_F(TApp, InvalidOptions) {
EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound);
}

TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
app.option_defaults()->ignore_case();
auto ogroup = app.add_option_group("clusters");
int res{0};
ogroup->add_option("--test1", res);

args = {"--Test1", "5"};
run();
EXPECT_EQ(res, 5);
EXPECT_EQ(app.count_all(), 1u);
}

struct ManyGroups : public TApp {

CLI::Option_group *main{nullptr};
Expand Down

0 comments on commit 6f589b8

Please sign in to comment.