Skip to content

Commit

Permalink
Merge pull request ipfs#2983 from yuvallanger/sort-subcommands
Browse files Browse the repository at this point in the history
Sort SUBCOMMANDS section of help output
  • Loading branch information
whyrusleeping authored Aug 3, 2016
2 parents 8405b56 + 7470ae5 commit 8c77ff8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions commands/cli/helptext.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,25 @@ func subcommandText(cmd *cmds.Command, rootName string, path []string) []string
if len(path) > 0 {
prefix += " "
}

// Sorting fixes changing order bug #2981.
sortedNames := make([]string, 0)
for name := range cmd.Subcommands {
sortedNames = append(sortedNames, name)
}
sort.Strings(sortedNames)

subcmds := make([]*cmds.Command, len(cmd.Subcommands))
lines := make([]string, len(cmd.Subcommands))

i := 0
for name, sub := range cmd.Subcommands {
for i, name := range sortedNames {
sub := cmd.Subcommands[name]
usage := usageText(sub)
if len(usage) > 0 {
usage = " " + usage
}
lines[i] = prefix + name + usage
subcmds[i] = sub
i++
}

lines = align(lines)
Expand Down

0 comments on commit 8c77ff8

Please sign in to comment.