Skip to content

Commit c31476b

Browse files
Multiple footer printing in help (#1161)
Fixes #1156 For option groups removes inheritance of the footer and help option, so those are not printed by default for option groups. It is still possible to set them again on the option group. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f6328cc commit c31476b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/CLI/App.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ class App {
733733
auto *ptr = option_group.get();
734734
// move to App_p for overload resolution on older gcc versions
735735
App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
736+
// don't inherit the footer in option groups and clear the help flag by default
737+
app_ptr->footer_ = "";
738+
app_ptr->set_help_flag();
736739
add_subcommand(std::move(app_ptr));
737740
return ptr;
738741
}

tests/HelpTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ TEST_CASE("THelp: FooterCallbackBoth", "[help]") {
8585
CHECK_THAT(help, Contains("foot!!!!"));
8686
}
8787

88+
/// @brief from github issue #1156
89+
TEST_CASE("THelp: FooterOptionGroup", "[help]") {
90+
CLI::App app{"My prog"};
91+
92+
app.footer("Report bugs to [email protected]");
93+
94+
app.add_option_group("group-a", "");
95+
96+
app.add_option_group("group-b", "");
97+
98+
std::string help = app.help();
99+
100+
auto footer_loc = help.find("[email protected]");
101+
auto footer_loc2 = help.find("[email protected]", footer_loc + 10);
102+
CHECK(footer_loc != std::string::npos);
103+
// should only see the footer once
104+
CHECK(footer_loc2 == std::string::npos);
105+
}
106+
88107
TEST_CASE("THelp: OptionalPositional", "[help]") {
89108
CLI::App app{"My prog", "program"};
90109

0 commit comments

Comments
 (0)