(w io.Writer)
| 25 | } |
| 26 | |
| 27 | func (cmd *Command) writeFishCompletionTemplate(w io.Writer) error { |
| 28 | const name = "cli" |
| 29 | t, err := template.New(name).Parse(FishCompletionTemplate) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | // Add global flags |
| 35 | completions := prepareFishFlags(cmd.Name, cmd) |
| 36 | |
| 37 | if cmd.ShellComplete != nil { |
| 38 | var completion strings.Builder |
| 39 | fmt.Fprintf(&completion, |
| 40 | "complete -c %s -n '%s' -xa '(%s %s 2>/dev/null)'", |
| 41 | cmd.Name, |
| 42 | fishFlagHelper(cmd.Name, cmd), |
| 43 | cmd.Name, |
| 44 | completionFlag, |
| 45 | ) |
| 46 | completions = append(completions, completion.String()) |
| 47 | } |
| 48 | |
| 49 | // Add commands and their flags |
| 50 | completions = append( |
| 51 | completions, |
| 52 | prepareFishCommands(cmd.Name, cmd)..., |
| 53 | ) |
| 54 | |
| 55 | toplevelCommandNames := []string{} |
| 56 | for _, child := range cmd.Commands { |
| 57 | toplevelCommandNames = append(toplevelCommandNames, child.Names()...) |
| 58 | } |
| 59 | |
| 60 | return t.ExecuteTemplate(w, name, &fishCommandCompletionTemplate{ |
| 61 | Command: cmd, |
| 62 | Completions: completions, |
| 63 | AllCommands: toplevelCommandNames, |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | func prepareFishCommands(binary string, parent *Command) []string { |
| 68 | commands := parent.Commands |
no test coverage detected