Commit e2270dd6f8507255065cf1c4f04f487f1b127f30

Authored by polistern
Committed by GitHub
1 parent 25274e2c

fix: fixed footer newline behavior (#796)

* fix: show newline before footer only if footer is set and not empty

* chore: tests corrected for new help message formatting.
include/CLI/impl/Formatter_inl.hpp
@@ -137,7 +137,7 @@ CLI11_INLINE std::string Formatter::make_footer(const App *app) const { @@ -137,7 +137,7 @@ CLI11_INLINE std::string Formatter::make_footer(const App *app) const {
137 if(footer.empty()) { 137 if(footer.empty()) {
138 return std::string{}; 138 return std::string{};
139 } 139 }
140 - return footer + "\n"; 140 + return "\n" + footer + "\n";
141 } 141 }
142 142
143 CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name, AppFormatMode mode) const { 143 CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name, AppFormatMode mode) const {
@@ -159,7 +159,7 @@ CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name, @@ -159,7 +159,7 @@ CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name,
159 out << make_positionals(app); 159 out << make_positionals(app);
160 out << make_groups(app, mode); 160 out << make_groups(app, mode);
161 out << make_subcommands(app, mode); 161 out << make_subcommands(app, mode);
162 - out << '\n' << make_footer(app); 162 + out << make_footer(app);
163 163
164 return out.str(); 164 return out.str();
165 } 165 }
tests/FormatterTest.cpp
@@ -63,7 +63,7 @@ TEST_CASE(&quot;Formatter: OptCustomize&quot;, &quot;[formatter]&quot;) { @@ -63,7 +63,7 @@ TEST_CASE(&quot;Formatter: OptCustomize&quot;, &quot;[formatter]&quot;) {
63 "Usage: [OPTIONS]\n\n" 63 "Usage: [OPTIONS]\n\n"
64 "Options:\n" 64 "Options:\n"
65 " -h,--help Print this help message and exit\n" 65 " -h,--help Print this help message and exit\n"
66 - " --opt INT (MUST HAVE) Something\n\n"); 66 + " --opt INT (MUST HAVE) Something\n");
67 } 67 }
68 68
69 TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") { 69 TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") {
@@ -82,7 +82,7 @@ TEST_CASE(&quot;Formatter: OptCustomizeSimple&quot;, &quot;[formatter]&quot;) { @@ -82,7 +82,7 @@ TEST_CASE(&quot;Formatter: OptCustomizeSimple&quot;, &quot;[formatter]&quot;) {
82 "Usage: [OPTIONS]\n\n" 82 "Usage: [OPTIONS]\n\n"
83 "Options:\n" 83 "Options:\n"
84 " -h,--help Print this help message and exit\n" 84 " -h,--help Print this help message and exit\n"
85 - " --opt INT (MUST HAVE) Something\n\n"); 85 + " --opt INT (MUST HAVE) Something\n");
86 } 86 }
87 87
88 TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") { 88 TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") {
@@ -100,7 +100,7 @@ TEST_CASE(&quot;Formatter: OptCustomizeOptionText&quot;, &quot;[formatter]&quot;) { @@ -100,7 +100,7 @@ TEST_CASE(&quot;Formatter: OptCustomizeOptionText&quot;, &quot;[formatter]&quot;) {
100 "Usage: [OPTIONS]\n\n" 100 "Usage: [OPTIONS]\n\n"
101 "Options:\n" 101 "Options:\n"
102 " -h,--help Print this help message and exit\n" 102 " -h,--help Print this help message and exit\n"
103 - " --opt (ARG) Something\n\n"); 103 + " --opt (ARG) Something\n");
104 } 104 }
105 105
106 TEST_CASE("Formatter: FalseFlagExample", "[formatter]") { 106 TEST_CASE("Formatter: FalseFlagExample", "[formatter]") {
@@ -140,7 +140,7 @@ TEST_CASE(&quot;Formatter: AppCustomize&quot;, &quot;[formatter]&quot;) { @@ -140,7 +140,7 @@ TEST_CASE(&quot;Formatter: AppCustomize&quot;, &quot;[formatter]&quot;) {
140 " -h,--help Print this help message and exit\n\n" 140 " -h,--help Print this help message and exit\n\n"
141 "Subcommands:\n" 141 "Subcommands:\n"
142 " subcom1 This\n" 142 " subcom1 This\n"
143 - " subcom2 This\n\n"); 143 + " subcom2 This\n");
144 } 144 }
145 145
146 TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") { 146 TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") {
@@ -159,7 +159,7 @@ TEST_CASE(&quot;Formatter: AppCustomizeSimple&quot;, &quot;[formatter]&quot;) { @@ -159,7 +159,7 @@ TEST_CASE(&quot;Formatter: AppCustomizeSimple&quot;, &quot;[formatter]&quot;) {
159 " -h,--help Print this help message and exit\n\n" 159 " -h,--help Print this help message and exit\n\n"
160 "Subcommands:\n" 160 "Subcommands:\n"
161 " subcom1 This\n" 161 " subcom1 This\n"
162 - " subcom2 This\n\n"); 162 + " subcom2 This\n");
163 } 163 }
164 164
165 TEST_CASE("Formatter: AllSub", "[formatter]") { 165 TEST_CASE("Formatter: AllSub", "[formatter]") {
tests/HelpTest.cpp
@@ -813,7 +813,7 @@ TEST_CASE_METHOD(CapturedHelp, &quot;CallForAllHelpOutput&quot;, &quot;[help]&quot;) { @@ -813,7 +813,7 @@ TEST_CASE_METHOD(CapturedHelp, &quot;CallForAllHelpOutput&quot;, &quot;[help]&quot;) {
813 " One description\n\n" 813 " One description\n\n"
814 "two\n" 814 "two\n"
815 " Options:\n" 815 " Options:\n"
816 - " --three \n\n\n"); 816 + " --three \n\n");
817 } 817 }
818 TEST_CASE_METHOD(CapturedHelp, "NewFormattedHelp", "[help]") { 818 TEST_CASE_METHOD(CapturedHelp, "NewFormattedHelp", "[help]") {
819 app.formatter_fn([](const CLI::App *, std::string, CLI::AppFormatMode) { return "New Help"; }); 819 app.formatter_fn([](const CLI::App *, std::string, CLI::AppFormatMode) { return "New Help"; });