1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

Aligment in multiline description (#269)

This commit is contained in:
elszon 2019-04-28 16:22:36 +02:00 committed by Henry Schreiner
parent b1036a1ad0
commit ca4bc6a6fc
2 changed files with 18 additions and 1 deletions

View File

@ -164,7 +164,12 @@ inline std::ostream &format_help(std::ostream &out, std::string name, std::strin
if(!description.empty()) { if(!description.empty()) {
if(name.length() >= wid) if(name.length() >= wid)
out << "\n" << std::setw(static_cast<int>(wid)) << ""; out << "\n" << std::setw(static_cast<int>(wid)) << "";
out << description; for(const char c : description) {
out.put(c);
if(c == '\n') {
out << std::setw(static_cast<int>(wid)) << "";
}
}
} }
out << "\n"; out << "\n";
return out; return out;

View File

@ -470,6 +470,18 @@ TEST(THelp, CustomHelp) {
} }
} }
TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) {
CLI::App app;
int i;
const std::string first{"first line"};
const std::string second{"second line"};
app.add_option("-i,--int", i, first + "\n" + second);
const std::string help = app.help();
const auto width = app.get_formatter()->get_column_width();
EXPECT_THAT(help, HasSubstr(first + "\n" + std::string(width, ' ') + second));
}
TEST(THelp, NiceName) { TEST(THelp, NiceName) {
CLI::App app; CLI::App app;