MCPcopy
hub / github.com/urfave/cli / writeFishCompletionTemplate

Method writeFishCompletionTemplate

fish.go:27–65  ·  fish.go::Command.writeFishCompletionTemplate
(w io.Writer)

Source from the content-addressed store, hash-verified

25}
26
27func (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
67func prepareFishCommands(binary string, parent *Command) []string {
68 commands := parent.Commands

Callers 1

ToFishCompletionMethod · 0.95

Calls 6

prepareFishFlagsFunction · 0.85
fishFlagHelperFunction · 0.85
prepareFishCommandsFunction · 0.85
ParseMethod · 0.65
NamesMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected