zsh: sort the commands to keep a determinist output

This commit is contained in:
Michael Muré 2018-12-27 20:08:32 +01:00
parent d2d81d9a96
commit 8da2943db0
No known key found for this signature in database
GPG key ID: A4457C029293126F

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"sort"
"strings" "strings"
) )
@ -81,16 +82,24 @@ func writeLevel(w io.Writer, root *Command, i int) {
commands := filterByLevel(root, i) commands := filterByLevel(root, i)
byParent := groupByParent(commands) byParent := groupByParent(commands)
for p, c := range byParent { // sort the parents to keep a determinist order
names := names(c) parents := make([]string, len(byParent))
fmt.Fprintf(w, " %s)\n", p) j := 0
for parent := range byParent {
parents[j] = parent
j++
}
sort.StringSlice(parents).Sort()
for _, parent := range parents {
names := names(byParent[parent])
fmt.Fprintf(w, " %s)\n", parent)
fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " "))
fmt.Fprintln(w, " ;;") fmt.Fprintln(w, " ;;")
} }
fmt.Fprintln(w, " *)") fmt.Fprintln(w, " *)")
fmt.Fprintln(w, " _arguments '*: :_files'") fmt.Fprintln(w, " _arguments '*: :_files'")
fmt.Fprintln(w, " ;;") fmt.Fprintln(w, " ;;")
} }
func filterByLevel(c *Command, l int) []*Command { func filterByLevel(c *Command, l int) []*Command {