From 93416cdebff12a3f85e694c8cb28350a5c14c50f Mon Sep 17 00:00:00 2001 From: Maiddog Date: Wed, 24 May 2017 19:20:04 -0500 Subject: Sort default help by group/command names Sort the default framework help functions by their group and command names. This should act as a reasonable default for users. If other behaviour is required, users can make their own or copy and modify existing functions. --- src/framework/help_commands.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/framework') diff --git a/src/framework/help_commands.rs b/src/framework/help_commands.rs index 1f38bd5..5d9a1f6 100644 --- a/src/framework/help_commands.rs +++ b/src/framework/help_commands.rs @@ -146,7 +146,11 @@ pub fn with_embeds(ctx: &mut Context, .description("To get help with an individual command, pass its \ name as an argument to this command."); - for (group_name, group) in groups { + let mut group_names = groups.keys().collect::>(); + group_names.sort(); + + for group_name in group_names { + let group = &groups[group_name]; let mut desc = String::new(); if let Some(ref x) = group.prefix { @@ -155,9 +159,15 @@ pub fn with_embeds(ctx: &mut Context, let mut no_commands = true; - for (n, cmd) in remove_aliases(&group.commands) { + let commands = remove_aliases(&group.commands); + let mut command_names = commands.keys().collect::>(); + command_names.sort(); + + for name in command_names { + let cmd = &commands[name]; + if cmd.help_available { - let _ = write!(desc, "`{}`\n", n); + let _ = write!(desc, "`{}`\n", name); no_commands = false; } @@ -255,7 +265,11 @@ pub fn plain(ctx: &mut Context, name as an argument to this command.\n\n" .to_string(); - for (group_name, group) in groups { + let mut group_names = groups.keys().collect::>(); + group_names.sort(); + + for group_name in group_names { + let group = &groups[group_name]; let _ = write!(result, "**{}:** ", group_name); if let Some(ref x) = group.prefix { @@ -264,9 +278,15 @@ pub fn plain(ctx: &mut Context, let mut no_commands = true; - for (n, cmd) in remove_aliases(&group.commands) { + let commands = remove_aliases(&group.commands); + let mut command_names = commands.keys().collect::>(); + command_names.sort(); + + for name in command_names { + let cmd = &commands[name]; + if cmd.help_available { - let _ = write!(result, "`{}` ", n); + let _ = write!(result, "`{}` ", name); no_commands = false; } -- cgit v1.2.3