From d859bff8771f6a053036daddf4186fe51fed6c6c Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 24 Aug 2020 08:35:16 +1200 Subject: [PATCH] Sort subcommands in the help text (#2396) --- crates/nu-cli/src/documentation.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/nu-cli/src/documentation.rs b/crates/nu-cli/src/documentation.rs index 7a6445f0e4..5b8268a895 100644 --- a/crates/nu-cli/src/documentation.rs +++ b/crates/nu-cli/src/documentation.rs @@ -131,13 +131,13 @@ pub fn get_documentation( long_desc.push_str(&cmd.usage()); long_desc.push_str("\n"); - let mut subcommands = String::new(); + let mut subcommands = vec![]; if !config.no_subcommands { for name in registry.names() { if name.starts_with(&format!("{} ", cmd_name)) { let subcommand = registry.get_command(&name).expect("This shouldn't happen"); - subcommands.push_str(&format!(" {} - {}\n", name, subcommand.usage())); + subcommands.push(format!(" {} - {}", name, subcommand.usage())); } } } @@ -173,7 +173,9 @@ pub fn get_documentation( if !subcommands.is_empty() { long_desc.push_str("\nSubcommands:\n"); - long_desc.push_str(&subcommands); + subcommands.sort(); + long_desc.push_str(&subcommands.join("\n")); + long_desc.push_str("\n"); } if !signature.positional.is_empty() || signature.rest_positional.is_some() {