Skip to content

Commit

Permalink
fix: fixed footer newline behavior (#796)
Browse files Browse the repository at this point in the history
* fix: show newline before footer only if footer is set and not empty

* chore: tests corrected for new help message formatting.
  • Loading branch information
polistern authored Oct 29, 2022
1 parent 25274e2 commit e2270dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/CLI/impl/Formatter_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CLI11_INLINE std::string Formatter::make_footer(const App *app) const {
if(footer.empty()) {
return std::string{};
}
return footer + "\n";
return "\n" + footer + "\n";
}

CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name, AppFormatMode mode) const {
Expand All @@ -159,7 +159,7 @@ CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name,
out << make_positionals(app);
out << make_groups(app, mode);
out << make_subcommands(app, mode);
out << '\n' << make_footer(app);
out << make_footer(app);

return out.str();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/FormatterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_CASE("Formatter: OptCustomize", "[formatter]") {
"Usage: [OPTIONS]\n\n"
"Options:\n"
" -h,--help Print this help message and exit\n"
" --opt INT (MUST HAVE) Something\n\n");
" --opt INT (MUST HAVE) Something\n");
}

TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") {
Expand All @@ -82,7 +82,7 @@ TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") {
"Usage: [OPTIONS]\n\n"
"Options:\n"
" -h,--help Print this help message and exit\n"
" --opt INT (MUST HAVE) Something\n\n");
" --opt INT (MUST HAVE) Something\n");
}

TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") {
Expand All @@ -100,7 +100,7 @@ TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") {
"Usage: [OPTIONS]\n\n"
"Options:\n"
" -h,--help Print this help message and exit\n"
" --opt (ARG) Something\n\n");
" --opt (ARG) Something\n");
}

TEST_CASE("Formatter: FalseFlagExample", "[formatter]") {
Expand Down Expand Up @@ -140,7 +140,7 @@ TEST_CASE("Formatter: AppCustomize", "[formatter]") {
" -h,--help Print this help message and exit\n\n"
"Subcommands:\n"
" subcom1 This\n"
" subcom2 This\n\n");
" subcom2 This\n");
}

TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") {
Expand All @@ -159,7 +159,7 @@ TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") {
" -h,--help Print this help message and exit\n\n"
"Subcommands:\n"
" subcom1 This\n"
" subcom2 This\n\n");
" subcom2 This\n");
}

TEST_CASE("Formatter: AllSub", "[formatter]") {
Expand Down
2 changes: 1 addition & 1 deletion tests/HelpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ TEST_CASE_METHOD(CapturedHelp, "CallForAllHelpOutput", "[help]") {
" One description\n\n"
"two\n"
" Options:\n"
" --three \n\n\n");
" --three \n\n");
}
TEST_CASE_METHOD(CapturedHelp, "NewFormattedHelp", "[help]") {
app.formatter_fn([](const CLI::App *, std::string, CLI::AppFormatMode) { return "New Help"; });
Expand Down

0 comments on commit e2270dd

Please sign in to comment.