(binary string, owner *Command)
| 120 | } |
| 121 | |
| 122 | func prepareFishFlags(binary string, owner *Command) []string { |
| 123 | flags := owner.VisibleFlags() |
| 124 | completions := []string{} |
| 125 | for _, f := range flags { |
| 126 | completion := &strings.Builder{} |
| 127 | fmt.Fprintf(completion, |
| 128 | "complete -c %s -n '%s'", |
| 129 | binary, |
| 130 | fishFlagHelper(binary, owner), |
| 131 | ) |
| 132 | |
| 133 | fishAddFileFlag(f, completion) |
| 134 | |
| 135 | for idx, opt := range f.Names() { |
| 136 | if idx == 0 { |
| 137 | fmt.Fprintf(completion, |
| 138 | " -l %s", strings.TrimSpace(opt), |
| 139 | ) |
| 140 | } else { |
| 141 | fmt.Fprintf(completion, |
| 142 | " -s %s", strings.TrimSpace(opt), |
| 143 | ) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if flag, ok := f.(DocGenerationFlag); ok { |
| 148 | if flag.TakesValue() { |
| 149 | completion.WriteString(" -r") |
| 150 | } |
| 151 | |
| 152 | if flag.GetUsage() != "" { |
| 153 | fmt.Fprintf(completion, |
| 154 | " -d '%s'", |
| 155 | escapeSingleQuotes(flag.GetUsage())) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | completions = append(completions, completion.String()) |
| 160 | } |
| 161 | |
| 162 | return completions |
| 163 | } |
| 164 | |
| 165 | func fishAddFileFlag(flag Flag, completion *strings.Builder) { |
| 166 | switch f := flag.(type) { |
no test coverage detected