From 1a99e03f88e0ab53e006b3d2e546841fa57f9901 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 2 Feb 2021 18:34:37 -0600 Subject: [PATCH] Sort commands in help output Closes #5 --- cmd/help.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/help.go b/cmd/help.go index f5f90fb..64e97be 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -32,7 +32,10 @@ func HelpCmd(args CmdArgs) (int, error) { func printHelp(commands map[string]Command) { var maxLen, cmdLen int + var keys []string + for _, c := range commands { + keys = append(keys, c.Name) cmdLen = len(c.Name) if cmdLen > maxLen { maxLen = cmdLen @@ -41,9 +44,11 @@ func printHelp(commands map[string]Command) { fmt.Printf("usage:\n lume []") fmt.Println() - fmt.Println("\ncommands:") - for _, c := range commands { + + sort.Strings(keys) + for _, k = range keys { + c := commands[k] fmt.Printf(" %-*s %s\n", maxLen, c.Name, c.Short) } }