Sort subcommands in the help text (#2396)

This commit is contained in:
Jonathan Turner 2020-08-24 08:35:16 +12:00 committed by GitHub
parent de5cd4ec23
commit d859bff877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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() {