From d8d05cb8077d7e9db354a72e73f2d944f62a2a8d Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 24 Mar 2023 09:55:13 +0300 Subject: [PATCH] Print tools in alphabetical order when no util choosen. --- src/multitool/main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/multitool/main.go b/src/multitool/main.go index 69ac86f..a2c3f6b 100644 --- a/src/multitool/main.go +++ b/src/multitool/main.go @@ -5,6 +5,7 @@ import( "os" path "path/filepath" "flag" + "sort" ) type Flags struct { @@ -34,9 +35,19 @@ func Main(name string, m Tools) { args = os.Args[:] } else { if len(os.Args)<2 { - for k, v := range m { - fmt.Printf("%s:\t%s\n", k, v.Desc) + keys := make([]string, len(m)) + i := 0 + for k, _ := range m { + keys[i] = k + i++ } + sort.Strings(keys) + + for _, k := range keys { + tool := m[k] + fmt.Printf("%s: %s\n", k, tool.Desc) + } + os.Exit(0) } utilName = os.Args[1]