diff options
author | Michael Muré <batolettre@gmail.com> | 2018-12-27 20:14:34 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-12-27 21:27:56 +0100 |
commit | 3f694195f86f22ac10e04bf0f0f70535fa30a4a0 (patch) | |
tree | a0d3ee081a1e402e6183852f0556753539d1ca48 /vendor/github.com/spf13/cobra | |
parent | 32b3e263fc8443f6089b9de8fbce833369461982 (diff) | |
download | git-bug-3f694195f86f22ac10e04bf0f0f70535fa30a4a0.tar.gz |
misc: fix non determinist zsh comp generation
upstream PR: https://github.com/spf13/cobra/pull/801
Diffstat (limited to 'vendor/github.com/spf13/cobra')
-rw-r--r-- | vendor/github.com/spf13/cobra/zsh_completions.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/vendor/github.com/spf13/cobra/zsh_completions.go b/vendor/github.com/spf13/cobra/zsh_completions.go index 889c22e2..e76d6071 100644 --- a/vendor/github.com/spf13/cobra/zsh_completions.go +++ b/vendor/github.com/spf13/cobra/zsh_completions.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "sort" "strings" ) @@ -81,16 +82,24 @@ func writeLevel(w io.Writer, root *Command, i int) { commands := filterByLevel(root, i) byParent := groupByParent(commands) - for p, c := range byParent { - names := names(c) - fmt.Fprintf(w, " %s)\n", p) + // sort the parents to keep a determinist order + parents := make([]string, len(byParent)) + 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.Fprintln(w, " ;;") } fmt.Fprintln(w, " *)") fmt.Fprintln(w, " _arguments '*: :_files'") fmt.Fprintln(w, " ;;") - } func filterByLevel(c *Command, l int) []*Command { |