Sort SUBCOMMANDS section of help output
License: MIT Signed-off-by: Yuval Langer <yuval.langer@gmail.com>
Yuval Langer committed
Jul 21, 2016 at 17:04 UTC
7470ae54280e39941993641c4efa4800e7be9402
1 file changed
+10
-3
commands/cli/helptext.go
+10
-3
@@ -351,18 +351,25 @@ func subcommandText(cmd *cmds.Command, rootName string, path []string) []string
351
if len(path) > 0 {
352
prefix += " "
353
}
354
+
355
+ // Sorting fixes changing order bug #2981.
356
+ sortedNames := make([]string, 0)
357
+ for name := range cmd.Subcommands {
358
+ sortedNames = append(sortedNames, name)
359
+ }
360
+ sort.Strings(sortedNames)
361
+
362
subcmds := make([]*cmds.Command, len(cmd.Subcommands))
363
lines := make([]string, len(cmd.Subcommands))
364
357
- i := 0
358
- for name, sub := range cmd.Subcommands {
365
+ for i, name := range sortedNames {
366
+ sub := cmd.Subcommands[name]
367
usage := usageText(sub)
368
if len(usage) > 0 {
369
usage = " " + usage
370
}
371
lines[i] = prefix + name + usage
372
subcmds[i] = sub
365
- i++
373
}
374
375
lines = align(lines)