Skip to content

Commit

Permalink
Sort default help by group/command names
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roughsketch authored and Zeyla Hellyer committed May 25, 2017
1 parent 77b5b48 commit 93416cd
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/framework/help_commands.rs
Expand Up @@ -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::<Vec<_>>();
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 {
Expand All @@ -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::<Vec<_>>();
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;
}
Expand Down Expand Up @@ -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::<Vec<_>>();
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 {
Expand All @@ -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::<Vec<_>>();
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;
}
Expand Down

0 comments on commit 93416cd

Please sign in to comment.