From 349d5c43cdbf583f66f6d679f1af794acf7750ec Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sun, 25 Sep 2016 08:59:46 +0200 Subject: [PATCH] sort output of -lists --- main.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 53c1745..45df67b 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "sort" "strings" ) @@ -21,7 +22,7 @@ func main() { flag.PrintDefaults() } - list := flag.String("list", "diceware", "name of list to use") + list := flag.String("list", "diceware", "name of list to use, see -lists") listLists := flag.Bool("lists", false, "list internal lists") dumpList := flag.Bool("dump", false, "dump the content of a -list") rolls := flag.Int("rolls", 6, "number of rolls for -electronic") @@ -34,7 +35,7 @@ func main() { flag.Parse() if *listLists { - for name, _ := range internalLists { + for _, name := range internalListNames() { fmt.Println(name) } return @@ -113,3 +114,14 @@ func listReaderFromString(list string) io.ReadCloser { } return gz } + +func internalListNames() []string { + names := make([]string, len(internalLists)) + i := 0 + for name, _ := range internalLists { + names[i] = name + i += 1 + } + sort.Strings(names) + return names +}