commands: sort commands by name

Michael Muré created

Change summary

Readme.md            |  3 +++
commands/commands.go | 15 +++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)

Detailed changes

Readme.md 🔗

@@ -64,6 +64,9 @@ git bug pull [<remote>]
 
 # Push bugs update to a git remote
 git bug push [<remote>]
+
+# Launch the web UI
+git bug webui 
 ```
 
 ## Internals

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