| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.22 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.22 io/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 8 | "text/templatescip-go gomod github.com/golang/go/src go1.22 `text/template`/" |
| 9 | ) |
| 10 | |
| 11 | // ToFishCompletion creates a fish completion string for the `*Command` |
| 12 | // The function errors if either parsing or writing of the string fails. |
| 13 | func (cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) ToFishCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ToFishCompletion().() (string, error) { |
| 14 | var w bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer# |
| 15 | if err := cmd.writeFishCompletionTemplatescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#writeFishCompletionTemplate().(&w); err != nil { |
| 16 | return "", err |
| 17 | } |
| 18 | return w.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), nil |
| 19 | } |
| 20 | |
| 21 | type fishCommandCompletionTemplatescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate# struct { |
| 22 | Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#Command. *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command# |
| 23 | Completionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#Completions. []string |
| 24 | AllCommandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#AllCommands. []string |
| 25 | } |
| 26 | |
| 27 | func (cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) writeFishCompletionTemplatescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#writeFishCompletionTemplate().(w ioscip-go gomod github.com/golang/go/src go1.22 io/.Writerscip-go gomod github.com/golang/go/src go1.22 io/Writer#) error { |
| 28 | const name = "cli" |
| 29 | t, err := templatescip-go gomod github.com/golang/go/src go1.22 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.22 `text/template`/New().(name).Parsescip-go gomod github.com/golang/go/src go1.22 `text/template`/Template#Parse().(FishCompletionTemplatescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FishCompletionTemplate.) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | // Add global flags |
| 35 | completions := prepareFishFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishFlags().(cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., cmd) |
| 36 | |
| 37 | if cmd.ShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellComplete. != nil { |
| 38 | var completion stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder# |
| 39 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(&completion, |
| 40 | "complete -c %s -n '%s' -xa '(%s %s 2>/dev/null)'", |
| 41 | cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., |
| 42 | fishFlagHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishFlagHelper().(cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., cmd), |
| 43 | cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., |
| 44 | completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag., |
| 45 | ) |
| 46 | completions = append(completions, completion.Stringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#String().()) |
| 47 | } |
| 48 | |
| 49 | // Add commands and their flags |
| 50 | completions = append( |
| 51 | completions, |
| 52 | prepareFishCommandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishCommands().(cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., cmd)..., |
| 53 | ) |
| 54 | |
| 55 | toplevelCommandNames := []string{} |
| 56 | for _, child := range cmd.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands. { |
| 57 | toplevelCommandNames = append(toplevelCommandNames, child.Namesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Names().()...) |
| 58 | } |
| 59 | |
| 60 | return t.ExecuteTemplatescip-go gomod github.com/golang/go/src go1.22 `text/template`/Template#ExecuteTemplate().(w, name, &fishCommandCompletionTemplatescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#{ |
| 61 | Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#Command.: cmd, |
| 62 | Completionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#Completions.: completions, |
| 63 | AllCommandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishCommandCompletionTemplate#AllCommands.: toplevelCommandNames, |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | func prepareFishCommandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishCommands().(binary string, parent *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) []string { |
| 68 | commands := parent.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands. |
| 69 | completions := []string{} |
| 70 | for _, command := range commands { |
| 71 | if !command.Hiddenscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Hidden. { |
| 72 | var completion stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder# |
| 73 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(&completion, |
| 74 | "complete -x -c %s -n '%s' -a '%s'", |
| 75 | binary, |
| 76 | fishSubcommandHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishSubcommandHelper().(binary, parent, commands), |
| 77 | command.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name., |
| 78 | ) |
| 79 | |
| 80 | if command.Usagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Usage. != "" { |
| 81 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(&completion, |
| 82 | " -d '%s'", |
| 83 | escapeSingleQuotesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/escapeSingleQuotes().(command.Usagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Usage.)) |
| 84 | } |
| 85 | completions = append(completions, completion.Stringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#String().()) |
| 86 | } |
| 87 | |
| 88 | if command.ShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellComplete. != nil { |
| 89 | var completion stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder# |
| 90 | var path []string |
| 91 | lineage := command.Lineagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Lineage().() |
| 92 | for i := len(lineage) - 2; i >= 0; i-- { |
| 93 | path = append(path, lineage[i].Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.) |
| 94 | } |
| 95 | |
| 96 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(&completion, |
| 97 | "complete -c %s -n '%s' -xa '(%s %s %s 2>/dev/null)'", |
| 98 | binary, |
| 99 | fishFlagHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishFlagHelper().(binary, command), |
| 100 | binary, |
| 101 | stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(path, " "), |
| 102 | completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag., |
| 103 | ) |
| 104 | completions = append(completions, completion.Stringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#String().()) |
| 105 | } |
| 106 | |
| 107 | completions = append( |
| 108 | completions, |
| 109 | prepareFishFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishFlags().(binary, command)..., |
| 110 | ) |
| 111 | |
| 112 | // recursively iterate subcommands |
| 113 | completions = append( |
| 114 | completions, |
| 115 | prepareFishCommandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishCommands().(binary, command)..., |
| 116 | ) |
| 117 | } |
| 118 | |
| 119 | return completions |
| 120 | } |
| 121 | |
| 122 | func prepareFishFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prepareFishFlags().(binary string, owner *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) []string { |
| 123 | flags := owner.VisibleFlagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#VisibleFlags().() |
| 124 | completions := []string{} |
| 125 | for _, f := range flags { |
| 126 | completion := &stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder#{} |
| 127 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(completion, |
| 128 | "complete -c %s -n '%s'", |
| 129 | binary, |
| 130 | fishFlagHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishFlagHelper().(binary, owner), |
| 131 | ) |
| 132 | |
| 133 | fishAddFileFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishAddFileFlag().(f, completion) |
| 134 | |
| 135 | for idx, opt := range f.Namesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#Names.() { |
| 136 | if idx == 0 { |
| 137 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(completion, |
| 138 | " -l %s", stringsscip-go gomod github.com/golang/go/src go1.22 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.22 strings/TrimSpace().(opt), |
| 139 | ) |
| 140 | } else { |
| 141 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(completion, |
| 142 | " -s %s", stringsscip-go gomod github.com/golang/go/src go1.22 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.22 strings/TrimSpace().(opt), |
| 143 | ) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if flag, ok := f.(DocGenerationFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#); ok { |
| 148 | if flag.TakesValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#TakesValue.() { |
| 149 | completion.WriteStringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#WriteString().(" -r") |
| 150 | } |
| 151 | |
| 152 | if flag.GetUsagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetUsage.() != "" { |
| 153 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintf().(completion, |
| 154 | " -d '%s'", |
| 155 | escapeSingleQuotesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/escapeSingleQuotes().(flag.GetUsagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetUsage.())) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | completions = append(completions, completion.Stringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#String().()) |
| 160 | } |
| 161 | |
| 162 | return completions |
| 163 | } |
| 164 | |
| 165 | func fishAddFileFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishAddFileFlag().(flag Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#, completion *stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder#) { |
| 166 | switch f := flag.(type) { |
| 167 | case *StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#: |
| 168 | if f.TakesFilescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#TakesFile. { |
| 169 | return |
| 170 | } |
| 171 | case *StringSliceFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringSliceFlag#: |
| 172 | if f.TakesFilescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#TakesFile. { |
| 173 | return |
| 174 | } |
| 175 | } |
| 176 | completion.WriteStringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#WriteString().(" -f") |
| 177 | } |
| 178 | |
| 179 | func fishSubcommandHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishSubcommandHelper().(binary string, command *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, siblings []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) string { |
| 180 | fishHelper := fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("__fish_%s_no_subcommand", binary) |
| 181 | if len(command.Lineagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Lineage().()) > 1 { |
| 182 | var siblingNames []string |
| 183 | for _, sibling := range siblings { |
| 184 | siblingNames = append(siblingNames, sibling.Namesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Names().()...) |
| 185 | } |
| 186 | ancestry := commandAncestryscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/commandAncestry().(command) |
| 187 | fishHelper = fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().( |
| 188 | "%s; and not __fish_seen_subcommand_from %s", |
| 189 | ancestry, |
| 190 | stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(siblingNames, " "), |
| 191 | ) |
| 192 | } |
| 193 | return fishHelper |
| 194 | } |
| 195 | |
| 196 | func fishFlagHelperscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/fishFlagHelper().(binary string, command *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) string { |
| 197 | fishHelper := fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("__fish_%s_no_subcommand", binary) |
| 198 | if len(command.Lineagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Lineage().()) > 1 { |
| 199 | fishHelper = commandAncestryscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/commandAncestry().(command) |
| 200 | } |
| 201 | return fishHelper |
| 202 | } |
| 203 | |
| 204 | func commandAncestryscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/commandAncestry().(command *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) string { |
| 205 | var ancestry []string |
| 206 | ancestors := command.Lineagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Lineage().() |
| 207 | for i := len(ancestors) - 2; i >= 0; i-- { |
| 208 | ancestry = append( |
| 209 | ancestry, |
| 210 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().( |
| 211 | "__fish_seen_subcommand_from %s", |
| 212 | stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(ancestors[i].Namesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Names().(), " "), |
| 213 | ), |
| 214 | ) |
| 215 | } |
| 216 | return stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(ancestry, "; and ") |
| 217 | } |
| 218 | |
| 219 | func escapeSingleQuotesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/escapeSingleQuotes().(input string) string { |
| 220 | return stringsscip-go gomod github.com/golang/go/src go1.22 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.22 strings/ReplaceAll().(input, `'`, `\'`) |
| 221 | } |