From 451c3b30ca4f4b009509dffbe9c98a4c3b7ffeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Mon, 16 Jul 2018 22:38:52 +0200 Subject: [PATCH] commands: sort commands by name --- Readme.md | 3 +++ commands/commands.go | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 6d1b5fd8d5cf3519ccdad8ffea3691ce7f4ea519..faecc61dce361bf6302865c2851a73c4fa30675c 100644 --- a/Readme.md +++ b/Readme.md @@ -64,6 +64,9 @@ git bug pull [] # Push bugs update to a git remote git bug push [] + +# Launch the web UI +git bug webui ``` ## Internals diff --git a/commands/commands.go b/commands/commands.go index 0a3c33ad968bc60d08bb0922a54c1deae5310372..1e8e9e19e47bf48d8a77db6f00eed5310bff61a4 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "github.com/MichaelMure/git-bug/repository" + "sort" ) var commandsFlagSet = flag.NewFlagSet("commands", flag.ExitOnError) @@ -18,19 +19,29 @@ func runCommands(repo repository.Repo, args []string) error { first := true - for name, cmd := range CommandMap { + keys := make([]string, 0, len(CommandMap)) + + for key := range CommandMap { + keys = append(keys, key) + } + + sort.Strings(keys) + + for _, key := range keys { if !first { fmt.Println() } first = false + cmd := CommandMap[key] + if *commandsDesc { fmt.Printf("# %s\n", cmd.Description) } // TODO: the root name command ("git bug") should be passed from git-bug.go but well ... - fmt.Printf("%s %s %s\n", "git bug", name, cmd.Usage) + fmt.Printf("%s %s %s\n", "git bug", key, cmd.Usage) } return nil