From 6c453aa5caf78fd755d1444e6020632c4df94914 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 24 Jun 2020 12:08:35 +0200 Subject: [PATCH] service: list commands in lexicographic order --- service.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index fc66c2c..78c67c4 100644 --- a/service.go +++ b/service.go @@ -17,6 +17,7 @@ import ( "fmt" "io/ioutil" "math/big" + "sort" "strings" "time" @@ -125,6 +126,15 @@ func (cmds serviceCommandSet) Get(params []string) (*serviceCommand, []string, e return cmd.children.Get(params) } +func (cmds serviceCommandSet) Names() []string { + l := make([]string, 0, len(cmds)) + for name := range cmds { + l = append(l, name) + } + sort.Strings(l) + return l +} + var serviceCommands serviceCommandSet func init() { @@ -196,7 +206,8 @@ func init() { } func appendServiceCommandSetHelp(cmds serviceCommandSet, prefix []string, admin bool, l *[]string) { - for name, cmd := range cmds { + for _, name := range cmds.Names() { + cmd := cmds[name] if cmd.admin && !admin { continue }