service: list commands in lexicographic order

This commit is contained in:
Simon Ser 2020-06-24 12:08:35 +02:00
parent 2232b3128b
commit 6c453aa5ca
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -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
}