Commit 2e157e98812ecf3a812d60f629044c38b5446b81

Authored by Pavel Medvedev
1 parent 774d455d

Skip empty lines in option groups help

Also use single character \n for end of line instead of string literal.
Showing 1 changed file with 9 additions and 8 deletions
src/cxxopts.hpp
@@ -884,7 +884,7 @@ namespace cxxopts @@ -884,7 +884,7 @@ namespace cxxopts
884 884
885 if (o.has_default) 885 if (o.has_default)
886 { 886 {
887 - desc += toLocalString(" (default:" + o.default_value + ")"); 887 + desc += toLocalString(" (default: " + o.default_value + ")");
888 } 888 }
889 889
890 String result; 890 String result;
@@ -1276,7 +1276,7 @@ Options::help_one_group(const std::string& g) const @@ -1276,7 +1276,7 @@ Options::help_one_group(const std::string& g) const
1276 1276
1277 if (!g.empty()) 1277 if (!g.empty())
1278 { 1278 {
1279 - result += toLocalString(" " + g + " options:\n\n"); 1279 + result += toLocalString(" " + g + " options:\n");
1280 } 1280 }
1281 1281
1282 for (const auto& o : group->second.options) 1282 for (const auto& o : group->second.options)
@@ -1299,7 +1299,7 @@ Options::help_one_group(const std::string& g) const @@ -1299,7 +1299,7 @@ Options::help_one_group(const std::string& g) const
1299 result += fiter->first; 1299 result += fiter->first;
1300 if (stringLength(fiter->first) > longest) 1300 if (stringLength(fiter->first) > longest)
1301 { 1301 {
1302 - result += "\n"; 1302 + result += '\n';
1303 result += toLocalString(std::string(longest + OPTION_DESC_GAP, ' ')); 1303 result += toLocalString(std::string(longest + OPTION_DESC_GAP, ' '));
1304 } 1304 }
1305 else 1305 else
@@ -1309,7 +1309,7 @@ Options::help_one_group(const std::string& g) const @@ -1309,7 +1309,7 @@ Options::help_one_group(const std::string& g) const
1309 ' ')); 1309 ' '));
1310 } 1310 }
1311 result += d; 1311 result += d;
1312 - result += "\n"; 1312 + result += '\n';
1313 1313
1314 ++fiter; 1314 ++fiter;
1315 } 1315 }
@@ -1320,15 +1320,16 @@ Options::help_one_group(const std::string& g) const @@ -1320,15 +1320,16 @@ Options::help_one_group(const std::string& g) const
1320 std::string 1320 std::string
1321 Options::help(const std::vector<std::string>& groups) const 1321 Options::help(const std::vector<std::string>& groups) const
1322 { 1322 {
1323 - String result = "Usage:\n " + toLocalString(m_program) + " [OPTION...]"  
1324 - + m_help_string + "\n\n"; 1323 + String result = m_help_string + "\nUsage:\n " + toLocalString(m_program) + " [OPTION...]\n\n";
1325 1324
1326 for (std::size_t i = 0; i < groups.size(); ++i) 1325 for (std::size_t i = 0; i < groups.size(); ++i)
1327 { 1326 {
1328 - result += help_one_group(groups[i]); 1327 + String const& group_help = help_one_group(groups[i]);
  1328 + if (group_help.empty()) continue;
  1329 + result += group_help;
1329 if (i < groups.size() - 1) 1330 if (i < groups.size() - 1)
1330 { 1331 {
1331 - result += "\n"; 1332 + result += '\n';
1332 } 1333 }
1333 } 1334 }
1334 1335