Commit ca4bc6a6fca359eb50b6c29a4b15dea7c1304e5c
Committed by
Henry Schreiner
1 parent
b1036a1a
Aligment in multiline description (#269)
Showing
2 changed files
with
18 additions
and
1 deletions
include/CLI/StringTools.hpp
| ... | ... | @@ -164,7 +164,12 @@ inline std::ostream &format_help(std::ostream &out, std::string name, std::strin |
| 164 | 164 | if(!description.empty()) { |
| 165 | 165 | if(name.length() >= wid) |
| 166 | 166 | out << "\n" << std::setw(static_cast<int>(wid)) << ""; |
| 167 | - out << description; | |
| 167 | + for(const char c : description) { | |
| 168 | + out.put(c); | |
| 169 | + if(c == '\n') { | |
| 170 | + out << std::setw(static_cast<int>(wid)) << ""; | |
| 171 | + } | |
| 172 | + } | |
| 168 | 173 | } |
| 169 | 174 | out << "\n"; |
| 170 | 175 | return out; | ... | ... |
tests/HelpTest.cpp
| ... | ... | @@ -470,6 +470,18 @@ TEST(THelp, CustomHelp) { |
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | +TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) { | |
| 474 | + CLI::App app; | |
| 475 | + int i; | |
| 476 | + const std::string first{"first line"}; | |
| 477 | + const std::string second{"second line"}; | |
| 478 | + app.add_option("-i,--int", i, first + "\n" + second); | |
| 479 | + | |
| 480 | + const std::string help = app.help(); | |
| 481 | + const auto width = app.get_formatter()->get_column_width(); | |
| 482 | + EXPECT_THAT(help, HasSubstr(first + "\n" + std::string(width, ' ') + second)); | |
| 483 | +} | |
| 484 | + | |
| 473 | 485 | TEST(THelp, NiceName) { |
| 474 | 486 | CLI::App app; |
| 475 | 487 | ... | ... |