From 261e0fabccad0e147592d41b38390bdef24dd69d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 4 Jun 2017 08:37:51 +0100 Subject: [PATCH] Improve readability of command docstrings by changing formatting Fixes #1378 --- src/command_manager.cc | 13 +++---------- src/commands.cc | 2 +- src/parameters_parser.cc | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index e2294b37..fa7a5044 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -538,26 +538,19 @@ Optional CommandManager::command_info(const Context& context, Strin } String helpstr = cmd->value.helper(context, params); if (not helpstr.empty()) - { - if (helpstr.back() != '\n') - helpstr += '\n'; - res.info += helpstr; - } + res.info += format("{}\n", helpstr); } String aliases; for (auto& alias : context.aliases().aliases_for(cmd->key)) aliases += " " + alias; if (not aliases.empty()) - res.info += "Aliases:" + aliases + "\n"; + res.info += format("Aliases:{}\n", aliases); auto& switches = cmd->value.param_desc.switches; if (not switches.empty()) - { - res.info += "Switches:\n"; - res.info += generate_switches_doc(switches); - } + res.info += format("Switches:\n{}", indent(generate_switches_doc(switches))); return res; } diff --git a/src/commands.cc b/src/commands.cc index 2f4df4bc..e2314c66 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1222,7 +1222,7 @@ static String option_doc_helper(const Context& context, CommandParameters params if (not desc or desc->docstring().empty()) return ""; - return format("{}: {}", desc->name(), desc->docstring()); + return format("{}:\n{}", desc->name(), indent(desc->docstring())); } static OptionManager& get_options(StringView scope, const Context& context, StringView option_name) diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc index 9ca475f7..b37e13d3 100644 --- a/src/parameters_parser.cc +++ b/src/parameters_parser.cc @@ -9,7 +9,7 @@ String generate_switches_doc(const SwitchMap& switches) { String res; for (auto& sw : switches) - res += format(" -{} {}: {}\n", sw.key, + res += format("-{} {}: {}\n", sw.key, sw.value.takes_arg ? "" : "", sw.value.description); return res;