| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.22 context/" |
| 5 | "embedscip-go gomod github.com/golang/go/src go1.22 embed/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 8 | ) |
| 9 | |
| 10 | const ( |
| 11 | completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName. = "completion" |
| 12 | |
| 13 | // This flag is supposed to only be used by the completion script itself to generate completions on the fly. |
| 14 | completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag. = "--generate-shell-completion" |
| 15 | ) |
| 16 | |
| 17 | type renderCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/renderCompletion# func(cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appName string) (string, error) |
| 18 | |
| 19 | var ( |
| 20 | //go:embed autocomplete |
| 21 | autoCompleteFSscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/autoCompleteFS. embedscip-go gomod github.com/golang/go/src go1.22 embed/.FSscip-go gomod github.com/golang/go/src go1.22 embed/FS# |
| 22 | |
| 23 | // completionShells defines the order in which the shell completion |
| 24 | // subcommands appear in help output. Iterating shellCompletions directly |
| 25 | // would use Go's randomized map order, making the listing nondeterministic. |
| 26 | // Keep this in sync with shellCompletions. |
| 27 | completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. = []string{"bash", "zsh", "fish", "pwsh"} |
| 28 | |
| 29 | shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions. = map[string]renderCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/renderCompletion#{ |
| 30 | "bash": func(cscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:c. *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName. string) (string, error) { |
| 31 | b, err := autoCompleteFSscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/autoCompleteFS..ReadFilescip-go gomod github.com/golang/go/src go1.22 embed/FS#ReadFile().("autocomplete/bash_autocomplete") |
| 32 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(string(b), appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName.), err |
| 33 | }, |
| 34 | "zsh": func(cscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:c. *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName. string) (string, error) { |
| 35 | b, err := autoCompleteFSscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/autoCompleteFS..ReadFilescip-go gomod github.com/golang/go/src go1.22 embed/FS#ReadFile().("autocomplete/zsh_autocomplete") |
| 36 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(string(b), appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName.), err |
| 37 | }, |
| 38 | "fish": func(cscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:c. *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName. string) (string, error) { |
| 39 | b, err := autoCompleteFSscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/autoCompleteFS..ReadFilescip-go gomod github.com/golang/go/src go1.22 embed/FS#ReadFile().("autocomplete/fish_autocomplete") |
| 40 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(string(b), appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName.), err |
| 41 | }, |
| 42 | "pwsh": func(cscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:c. *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions:appName. string) (string, error) { |
| 43 | b, err := autoCompleteFSscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/autoCompleteFS..ReadFilescip-go gomod github.com/golang/go/src go1.22 embed/FS#ReadFile().("autocomplete/powershell_autocomplete.ps1") |
| 44 | return string(b), err |
| 45 | }, |
| 46 | } |
| 47 | ) |
| 48 | |
| 49 | const completionDescriptionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionDescription. = `Output shell completion script for bash, zsh, fish, or Powershell. |
| 50 | Source the output to enable completion. |
| 51 | |
| 52 | # .bashrc |
| 53 | source <($COMMAND completion bash) |
| 54 | |
| 55 | # .zshrc |
| 56 | source <($COMMAND completion zsh) |
| 57 | |
| 58 | # fish |
| 59 | $COMMAND completion fish > ~/.config/fish/completions/$COMMAND.fish |
| 60 | |
| 61 | # Powershell |
| 62 | Output the script to path/to/autocomplete/$COMMAND.ps1 an run it. |
| 63 | ` |
| 64 | |
| 65 | func buildCompletionCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildCompletionCommand().(appName string) *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command# { |
| 66 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 67 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., |
| 68 | Hiddenscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Hidden.: true, |
| 69 | Usagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Usage.: "Output shell completion script for bash, zsh, fish, or Powershell", |
| 70 | Descriptionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Description.: stringsscip-go gomod github.com/golang/go/src go1.22 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.22 strings/ReplaceAll().(completionDescriptionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionDescription., "$COMMAND", appName), |
| 71 | isCompletionCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#isCompletionCommand.: true, |
| 72 | } |
| 73 | |
| 74 | for _, shell := range completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. { |
| 75 | cmd.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands. = append(cmd.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands., buildShellCompletionSubcommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildShellCompletionSubcommand().(shell, shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.[shell], appName)) |
| 76 | } |
| 77 | |
| 78 | return cmd |
| 79 | } |
| 80 | |
| 81 | func buildShellCompletionSubcommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildShellCompletionSubcommand().(shell string, render renderCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/renderCompletion#, appName string) *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command# { |
| 82 | return &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 83 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: shell, |
| 84 | Usagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Usage.: fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("Output %s completion script", shell), |
| 85 | isCompletionCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#isCompletionCommand.: true, |
| 86 | Actionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Action.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) error { |
| 87 | completionScript, err := render(cmd, appName) |
| 88 | if err != nil { |
| 89 | return Exitscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Exit().(err, 1) |
| 90 | } |
| 91 | _, err = cmd.Rootscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Root().().Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer..Writescip-go gomod github.com/golang/go/src go1.22 io/Writer#Write().([]byte(completionScript)) |
| 92 | if err != nil { |
| 93 | return Exitscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Exit().(err, 1) |
| 94 | } |
| 95 | return nil |
| 96 | }, |
| 97 | } |
| 98 | } |