mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
zsh: sort the commands to keep a determinist output
This commit is contained in:
parent
d2d81d9a96
commit
8da2943db0
1 changed files with 13 additions and 4 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue