mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 14:03:52 +00:00
fix issue with option defaults not propagating to option groups (#450)
This commit is contained in:
parent
eb1150d6be
commit
6f589b8443
@ -975,7 +975,7 @@ class App {
|
|||||||
/// creates an option group as part of the given app
|
/// creates an option group as part of the given app
|
||||||
template <typename T = Option_group>
|
template <typename T = Option_group>
|
||||||
T *add_option_group(std::string group_name, std::string group_description = "") {
|
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();
|
auto ptr = option_group.get();
|
||||||
// move to App_p for overload resolution on older gcc versions
|
// move to App_p for overload resolution on older gcc versions
|
||||||
App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
|
App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
|
||||||
|
@ -368,6 +368,18 @@ TEST_F(TApp, InvalidOptions) {
|
|||||||
EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound);
|
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 {
|
struct ManyGroups : public TApp {
|
||||||
|
|
||||||
CLI::Option_group *main{nullptr};
|
CLI::Option_group *main{nullptr};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user