diff --git a/app.go b/app.go index 51b2672a38..4b88c3a121 100644 --- a/app.go +++ b/app.go @@ -51,8 +51,10 @@ type App struct { Commands []*Command // List of flags to parse Flags []Flag - // Boolean to enable bash completion commands - EnableBashCompletion bool + // Boolean to enable shell completion commands + EnableShellCompletion bool + // Shell Completion generation command name + ShellCompletionCommandName string // Boolean to hide built-in help command and help flag HideHelp bool // Boolean to hide built-in help command but keep help flag. @@ -65,7 +67,7 @@ type App struct { // flagCategories contains the categorized flags and is populated on app startup flagCategories FlagCategories // An action to execute when the shell completion flag is set - BashComplete BashCompleteFunc + ShellComplete ShellCompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run Before BeforeFunc @@ -131,14 +133,14 @@ type SuggestCommandFunc func(commands []*Command, provided string) string // Usage, Version and Action. func NewApp() *App { return &App{ - Name: filepath.Base(os.Args[0]), - Usage: "A new cli application", - UsageText: "", - BashComplete: DefaultAppComplete, - Action: helpCommand.Action, - Reader: os.Stdin, - Writer: os.Stdout, - ErrWriter: os.Stderr, + Name: filepath.Base(os.Args[0]), + Usage: "A new cli application", + UsageText: "", + ShellComplete: DefaultAppComplete, + Action: helpCommand.Action, + Reader: os.Stdin, + Writer: os.Stdout, + ErrWriter: os.Stderr, } } @@ -168,8 +170,8 @@ func (a *App) Setup() { a.HideVersion = true } - if a.BashComplete == nil { - a.BashComplete = DefaultAppComplete + if a.ShellComplete == nil { + a.ShellComplete = DefaultAppComplete } if a.Action == nil { @@ -227,6 +229,13 @@ func (a *App) Setup() { a.appendFlag(VersionFlag) } + if a.EnableShellCompletion { + if a.ShellCompletionCommandName != "" { + completionCommand.Name = a.ShellCompletionCommandName + } + a.appendCommand(completionCommand) + } + a.categories = newCommandCategories() for _, command := range a.Commands { a.categories.AddCommand(command.Category, command) @@ -260,7 +269,7 @@ func (a *App) newRootCommand() *Command { UsageText: a.UsageText, Description: a.Description, ArgsUsage: a.ArgsUsage, - BashComplete: a.BashComplete, + ShellComplete: a.ShellComplete, Before: a.Before, After: a.After, Action: a.Action, diff --git a/app_test.go b/app_test.go index 89196ff2e5..49e1ff65e2 100644 --- a/app_test.go +++ b/app_test.go @@ -232,11 +232,11 @@ func ExampleApp_Run_subcommandNoAction() { func ExampleApp_Run_bashComplete_withShortFlag() { os.Setenv("SHELL", "bash") - os.Args = []string{"greet", "-", "--generate-bash-completion"} + os.Args = []string{"greet", "-", "--generate-shell-completion"} app := NewApp() app.Name = "greet" - app.EnableBashCompletion = true + app.EnableShellCompletion = true app.Flags = []Flag{ &IntFlag{ Name: "other", @@ -260,11 +260,11 @@ func ExampleApp_Run_bashComplete_withShortFlag() { func ExampleApp_Run_bashComplete_withLongFlag() { os.Setenv("SHELL", "bash") - os.Args = []string{"greet", "--s", "--generate-bash-completion"} + os.Args = []string{"greet", "--s", "--generate-shell-completion"} app := NewApp() app.Name = "greet" - app.EnableBashCompletion = true + app.EnableShellCompletion = true app.Flags = []Flag{ &IntFlag{ Name: "other", @@ -290,11 +290,11 @@ func ExampleApp_Run_bashComplete_withLongFlag() { func ExampleApp_Run_bashComplete_withMultipleLongFlag() { os.Setenv("SHELL", "bash") - os.Args = []string{"greet", "--st", "--generate-bash-completion"} + os.Args = []string{"greet", "--st", "--generate-shell-completion"} app := NewApp() app.Name = "greet" - app.EnableBashCompletion = true + app.EnableShellCompletion = true app.Flags = []Flag{ &IntFlag{ Name: "int-flag", @@ -323,11 +323,11 @@ func ExampleApp_Run_bashComplete_withMultipleLongFlag() { func ExampleApp_Run_bashComplete() { os.Setenv("SHELL", "bash") - os.Args = []string{"greet", "--generate-bash-completion"} + os.Args = []string{"greet", "--generate-shell-completion"} app := &App{ - Name: "greet", - EnableBashCompletion: true, + Name: "greet", + EnableShellCompletion: true, Commands: []*Command{ { Name: "describeit", @@ -361,12 +361,12 @@ func ExampleApp_Run_bashComplete() { func ExampleApp_Run_zshComplete() { // set args for examples sake - os.Args = []string{"greet", "--generate-bash-completion"} + os.Args = []string{"greet", "--generate-shell-completion"} _ = os.Setenv("SHELL", "/usr/bin/zsh") app := NewApp() app.Name = "greet" - app.EnableBashCompletion = true + app.EnableShellCompletion = true app.Commands = []*Command{ { Name: "describeit", @@ -1369,7 +1369,7 @@ func TestApp_BeforeAfterFuncShellCompletion(t *testing.T) { var err error app := &App{ - EnableBashCompletion: true, + EnableShellCompletion: true, Before: func(*Context) error { counts.Total++ counts.Before = counts.Total @@ -1397,7 +1397,7 @@ func TestApp_BeforeAfterFuncShellCompletion(t *testing.T) { } // run with the Before() func succeeding - err = app.Run([]string{"command", "--opt", "succeed", "sub", "--generate-bash-completion"}) + err = app.Run([]string{"command", "--opt", "succeed", "sub", "--generate-shell-completion"}) if err != nil { t.Fatalf("Run error: %s", err) @@ -1736,8 +1736,8 @@ func TestApp_OrderOfOperations(t *testing.T) { resetCounts := func() { counts = &opCounts{} } app := &App{ - EnableBashCompletion: true, - BashComplete: func(*Context) { + EnableShellCompletion: true, + ShellComplete: func(*Context) { counts.Total++ counts.ShellComplete = counts.Total }, @@ -1803,7 +1803,7 @@ func TestApp_OrderOfOperations(t *testing.T) { resetCounts() - _ = app.Run([]string{"command", fmt.Sprintf("--%s", "generate-bash-completion")}) + _ = app.Run([]string{"command", fmt.Sprintf("--%s", "generate-shell-completion")}) expect(t, counts.ShellComplete, 1) expect(t, counts.Total, 1) @@ -2618,8 +2618,8 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) { Name: "test-completion", }, }, - EnableBashCompletion: true, - BashComplete: func(ctx *Context) { + EnableShellCompletion: true, + ShellComplete: func(ctx *Context) { for _, command := range ctx.App.Commands { if command.Hidden { continue @@ -2651,7 +2651,7 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) { }, Writer: io.Discard, } - err := app.Run([]string{"", "--test-completion", "--" + "generate-bash-completion"}) + err := app.Run([]string{"", "--test-completion", "--" + "generate-shell-completion"}) if err != nil { t.Errorf("app should not return an error: %s", err) } diff --git a/autocomplete/bash_autocomplete b/autocomplete/bash_autocomplete index f0f624183b..2c88b4f703 100755 --- a/autocomplete/bash_autocomplete +++ b/autocomplete/bash_autocomplete @@ -8,9 +8,9 @@ _cli_bash_autocomplete() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" if [[ "$cur" == "-"* ]]; then - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-shell-completion ) else - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-shell-completion ) fi COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 diff --git a/autocomplete/powershell_autocomplete.ps1 b/autocomplete/powershell_autocomplete.ps1 index 81812a6a43..cbf76942dd 100644 --- a/autocomplete/powershell_autocomplete.ps1 +++ b/autocomplete/powershell_autocomplete.ps1 @@ -2,7 +2,7 @@ $fn = $($MyInvocation.MyCommand.Name) $name = $fn -replace "(.*)\.ps1$", '$1' Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) - $other = "$wordToComplete --generate-bash-completion" + $other = "$wordToComplete --generate-shell-completion" Invoke-Expression $other | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } diff --git a/autocomplete/zsh_autocomplete b/autocomplete/zsh_autocomplete index b519666f80..622143dc2b 100644 --- a/autocomplete/zsh_autocomplete +++ b/autocomplete/zsh_autocomplete @@ -5,9 +5,9 @@ _cli_zsh_autocomplete() { local cur cur=${words[-1]} if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-shell-completion)}") else - opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}") fi if [[ "${opts[1]}" != "" ]]; then diff --git a/command.go b/command.go index bf9ce01b83..e2a8b33be5 100644 --- a/command.go +++ b/command.go @@ -24,8 +24,8 @@ type Command struct { ArgsUsage string // The category the command is part of Category string - // The function to call when checking for bash command completions - BashComplete BashCompleteFunc + // The function to call when checking for shell command completions + ShellComplete ShellCompleteFunc // An action to execute before any sub-subcommands are run, but after the context is ready // If a non-nil error is returned, no sub-subcommands are run Before BeforeFunc @@ -107,6 +107,9 @@ func (cmd *Command) Command(name string) *Command { } func (c *Command) setup(ctx *Context) { + if c.ShellComplete == nil { + c.ShellComplete = DefaultCompleteWithFlags(c) + } if c.Command(helpCommand.Name) == nil && !c.HideHelp { if !c.HideHelpCommand { helpCommand.HelpName = fmt.Sprintf("%s %s", c.HelpName, helpName) @@ -149,11 +152,7 @@ func (c *Command) Run(cCtx *Context, arguments ...string) (err error) { set, err := c.parseFlags(&a, cCtx) cCtx.flagSet = set - if c.isRoot { - if checkCompletions(cCtx) { - return nil - } - } else if checkCommandCompletions(cCtx, c.Name) { + if checkCompletions(cCtx) { return nil } diff --git a/command_test.go b/command_test.go index 011ec85d90..9ae6886566 100644 --- a/command_test.go +++ b/command_test.go @@ -349,8 +349,8 @@ func TestCommand_Run_CustomShellCompleteAcceptsMalformedFlags(t *testing.T) { for _, c := range cases { var outputBuffer bytes.Buffer app := &App{ - Writer: &outputBuffer, - EnableBashCompletion: true, + Writer: &outputBuffer, + EnableShellCompletion: true, Commands: []*Command{ { Name: "bar", @@ -361,7 +361,7 @@ func TestCommand_Run_CustomShellCompleteAcceptsMalformedFlags(t *testing.T) { Usage: "A number to parse", }, }, - BashComplete: func(c *Context) { + ShellComplete: func(c *Context) { fmt.Fprintf(c.App.Writer, "found %d args", c.NArg()) }, }, @@ -370,7 +370,7 @@ func TestCommand_Run_CustomShellCompleteAcceptsMalformedFlags(t *testing.T) { osArgs := args{"foo", "bar"} osArgs = append(osArgs, c.testArgs...) - osArgs = append(osArgs, "--generate-bash-completion") + osArgs = append(osArgs, "--generate-shell-completion") err := app.Run(osArgs) stdout := outputBuffer.String() diff --git a/completion.go b/completion.go new file mode 100644 index 0000000000..b124ca9806 --- /dev/null +++ b/completion.go @@ -0,0 +1,61 @@ +package cli + +import ( + "embed" + "fmt" + "sort" +) + +const ( + completionCommandName = "generate-completion" +) + +var ( + //go:embed autocomplete + autoCompleteFS embed.FS + + shellCompletions = map[string]renderCompletion{ + "bash": getCompletion("autocomplete/bash_autocomplete"), + "ps": getCompletion("autocomplete/powershell_autocomplete.ps1"), + "zsh": getCompletion("autocomplete/zsh_autocomplete"), + "fish": func(a *App) (string, error) { + return a.ToFishCompletion() + }, + } +) + +type renderCompletion func(a *App) (string, error) + +func getCompletion(s string) renderCompletion { + return func(a *App) (string, error) { + b, err := autoCompleteFS.ReadFile(s) + return string(b), err + } +} + +var completionCommand = &Command{ + Name: completionCommandName, + Hidden: true, + Action: func(ctx *Context) error { + var shells []string + for k := range shellCompletions { + shells = append(shells, k) + } + + sort.Strings(shells) + + if ctx.Args().Len() == 0 { + return Exit(fmt.Sprintf("no shell provided for completion command. available shells are %+v", shells), 1) + } + s := ctx.Args().First() + + if rc, ok := shellCompletions[s]; !ok { + return Exit(fmt.Sprintf("unknown shell %s, available shells are %+v", s, shells), 1) + } else if c, err := rc(ctx.App); err != nil { + return Exit(err, 1) + } else { + ctx.App.Writer.Write([]byte(c)) + } + return nil + }, +} diff --git a/completion_test.go b/completion_test.go new file mode 100644 index 0000000000..64310ae98e --- /dev/null +++ b/completion_test.go @@ -0,0 +1,70 @@ +package cli + +import ( + "bytes" + "strings" + "testing" +) + +func TestCompletionDisable(t *testing.T) { + a := &App{} + err := a.Run([]string{"foo", completionCommandName}) + if err == nil { + t.Error("Expected error for no help topic for completion") + } +} + +func TestCompletionEnable(t *testing.T) { + a := &App{ + EnableShellCompletion: true, + } + err := a.Run([]string{"foo", completionCommandName}) + if err == nil || !strings.Contains(err.Error(), "no shell provided") { + t.Errorf("expected no shell provided error instead got [%v]", err) + } +} + +func TestCompletionEnableDiffCommandName(t *testing.T) { + defer func() { + completionCommand.Name = completionCommandName + }() + + a := &App{ + EnableShellCompletion: true, + ShellCompletionCommandName: "junky", + } + err := a.Run([]string{"foo", "junky"}) + if err == nil || !strings.Contains(err.Error(), "no shell provided") { + t.Errorf("expected no shell provided error instead got [%v]", err) + } +} + +func TestCompletionShell(t *testing.T) { + for k := range shellCompletions { + var b bytes.Buffer + t.Run(k, func(t *testing.T) { + a := &App{ + EnableShellCompletion: true, + Writer: &b, + } + err := a.Run([]string{"foo", completionCommandName, k}) + if err != nil { + t.Error(err) + } + }) + output := b.String() + if !strings.Contains(output, k) { + t.Errorf("Expected output to contain shell name %v", output) + } + } +} + +func TestCompletionInvalidShell(t *testing.T) { + a := &App{ + EnableShellCompletion: true, + } + err := a.Run([]string{"foo", completionCommandName, "junky-sheell"}) + if err == nil { + t.Error("Expected error for invalid shell") + } +} diff --git a/fish.go b/fish.go index 99fd9a240b..545ab04aa4 100644 --- a/fish.go +++ b/fish.go @@ -115,11 +115,6 @@ func (a *App) prepareFishCommands(commands []*Command, allCommands *[]string, pr func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string { completions := []string{} for _, f := range flags { - flag, ok := f.(DocGenerationFlag) - if !ok { - continue - } - completion := &strings.Builder{} completion.WriteString(fmt.Sprintf( "complete -c %s -n '%s'", @@ -129,7 +124,7 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string fishAddFileFlag(f, completion) - for idx, opt := range flag.Names() { + for idx, opt := range f.Names() { if idx == 0 { completion.WriteString(fmt.Sprintf( " -l %s", strings.TrimSpace(opt), @@ -142,13 +137,15 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string } } - if flag.TakesValue() { - completion.WriteString(" -r") - } + if flag, ok := f.(DocGenerationFlag); ok { + if flag.TakesValue() { + completion.WriteString(" -r") + } - if flag.GetUsage() != "" { - completion.WriteString(fmt.Sprintf(" -d '%s'", - escapeSingleQuotes(flag.GetUsage()))) + if flag.GetUsage() != "" { + completion.WriteString(fmt.Sprintf(" -d '%s'", + escapeSingleQuotes(flag.GetUsage()))) + } } completions = append(completions, completion.String()) diff --git a/flag.go b/flag.go index 4844b0709f..a4d037505c 100644 --- a/flag.go +++ b/flag.go @@ -29,7 +29,7 @@ var ( // BashCompletionFlag enables bash-completion for all commands and subcommands var BashCompletionFlag Flag = &BoolFlag{ - Name: "generate-bash-completion", + Name: "generate-shell-completion", Hidden: true, } diff --git a/funcs.go b/funcs.go index e77b0d0a10..6bb33cfd16 100644 --- a/funcs.go +++ b/funcs.go @@ -1,7 +1,7 @@ package cli -// BashCompleteFunc is an action to execute when the shell completion flag is set -type BashCompleteFunc func(*Context) +// ShellCompleteFunc is an action to execute when the shell completion flag is set +type ShellCompleteFunc func(*Context) // BeforeFunc is an action to execute before any subcommands are run, but after // the context is ready if a non-nil error is returned, no subcommands are run diff --git a/godoc-current.txt b/godoc-current.txt index a4e036707c..b20c580569 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -212,9 +212,6 @@ func ShowAppHelpAndExit(c *Context, exitCode int) ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. -func ShowCommandCompletions(ctx *Context, command string) - ShowCommandCompletions prints the custom completions for a given command - func ShowCommandHelp(ctx *Context, command string) error ShowCommandHelp prints help for the given command @@ -273,8 +270,10 @@ type App struct { Commands []*Command // List of flags to parse Flags []Flag - // Boolean to enable bash completion commands - EnableBashCompletion bool + // Boolean to enable shell completion commands + EnableShellCompletion bool + // Shell Completion generation command name + ShellCompletionCommandName string // Boolean to hide built-in help command and help flag HideHelp bool // Boolean to hide built-in help command but keep help flag. @@ -284,7 +283,7 @@ type App struct { HideVersion bool // An action to execute when the shell completion flag is set - BashComplete BashCompleteFunc + ShellComplete ShellCompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run Before BeforeFunc @@ -432,10 +431,6 @@ func (a *Author) String() string String makes Author comply to the Stringer interface, to allow an easy print in the templating process -type BashCompleteFunc func(*Context) - BashCompleteFunc is an action to execute when the shell completion flag is - set - type BeforeFunc func(*Context) error BeforeFunc is an action to execute before any subcommands are run, but after the context is ready if a non-nil error is returned, no subcommands are run @@ -471,8 +466,8 @@ type Command struct { ArgsUsage string // The category the command is part of Category string - // The function to call when checking for bash command completions - BashComplete BashCompleteFunc + // The function to call when checking for shell command completions + ShellComplete ShellCompleteFunc // An action to execute before any sub-subcommands are run, but after the context is ready // If a non-nil error is returned, no sub-subcommands are run Before BeforeFunc @@ -756,7 +751,7 @@ type Flag interface { implemented. var BashCompletionFlag Flag = &BoolFlag{ - Name: "generate-bash-completion", + Name: "generate-shell-completion", Hidden: true, } BashCompletionFlag enables bash-completion for all commands and subcommands @@ -999,6 +994,10 @@ type Serializer interface { } Serializer is used to circumvent the limitations of flag.FlagSet.Set +type ShellCompleteFunc func(*Context) + ShellCompleteFunc is an action to execute when the shell completion flag is + set + type SliceBase[T any, C any, VC ValueCreator[T, C]] struct { // Has unexported fields. } diff --git a/help.go b/help.go index a716ffae22..b4e3d1fa45 100644 --- a/help.go +++ b/help.go @@ -311,21 +311,9 @@ func printVersion(cCtx *Context) { // ShowCompletions prints the lists of commands within a given context func ShowCompletions(cCtx *Context) { - a := cCtx.App - if a != nil && a.BashComplete != nil { - a.BashComplete(cCtx) - } -} - -// ShowCommandCompletions prints the custom completions for a given command -func ShowCommandCompletions(ctx *Context, command string) { - c := ctx.App.Command(command) + c := cCtx.Command if c != nil { - if c.BashComplete != nil { - c.BashComplete(ctx) - } else { - DefaultCompleteWithFlags(c)(ctx) - } + c.ShellComplete(cCtx) } } @@ -415,14 +403,14 @@ func checkHelp(cCtx *Context) bool { } func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { - if !a.EnableBashCompletion { + if !a.EnableShellCompletion { return false, arguments } pos := len(arguments) - 1 lastArg := arguments[pos] - if lastArg != "--generate-bash-completion" { + if lastArg != "--generate-shell-completion" { return false, arguments } @@ -436,7 +424,7 @@ func checkCompletions(cCtx *Context) bool { if args := cCtx.Args(); args.Present() { name := args.First() - if cmd := cCtx.App.Command(name); cmd != nil { + if cmd := cCtx.Command.Command(name); cmd != nil { // let the command handle the completion return false } @@ -446,15 +434,6 @@ func checkCompletions(cCtx *Context) bool { return true } -func checkCommandCompletions(c *Context, name string) bool { - if !c.shellComplete { - return false - } - - ShowCommandCompletions(c, name) - return true -} - func subtract(a, b int) int { return a - b } diff --git a/help_test.go b/help_test.go index d7299dfa79..5f5a56457f 100644 --- a/help_test.go +++ b/help_test.go @@ -1316,7 +1316,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) { &StringFlag{Name: "hat-shape"}, }, }, - argv: []string{"cmd", "--e", "--generate-bash-completion"}, + argv: []string{"cmd", "--e", "--generate-shell-completion"}, expected: "--excitement\n", }, { @@ -1338,7 +1338,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) { &StringFlag{Name: "hat-shape"}, }, }, - argv: []string{"cmd", "--generate-bash-completion"}, + argv: []string{"cmd", "--generate-shell-completion"}, expected: "futz\n", }, } { diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt index a4e036707c..b20c580569 100644 --- a/testdata/godoc-v3.x.txt +++ b/testdata/godoc-v3.x.txt @@ -212,9 +212,6 @@ func ShowAppHelpAndExit(c *Context, exitCode int) ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. -func ShowCommandCompletions(ctx *Context, command string) - ShowCommandCompletions prints the custom completions for a given command - func ShowCommandHelp(ctx *Context, command string) error ShowCommandHelp prints help for the given command @@ -273,8 +270,10 @@ type App struct { Commands []*Command // List of flags to parse Flags []Flag - // Boolean to enable bash completion commands - EnableBashCompletion bool + // Boolean to enable shell completion commands + EnableShellCompletion bool + // Shell Completion generation command name + ShellCompletionCommandName string // Boolean to hide built-in help command and help flag HideHelp bool // Boolean to hide built-in help command but keep help flag. @@ -284,7 +283,7 @@ type App struct { HideVersion bool // An action to execute when the shell completion flag is set - BashComplete BashCompleteFunc + ShellComplete ShellCompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run Before BeforeFunc @@ -432,10 +431,6 @@ func (a *Author) String() string String makes Author comply to the Stringer interface, to allow an easy print in the templating process -type BashCompleteFunc func(*Context) - BashCompleteFunc is an action to execute when the shell completion flag is - set - type BeforeFunc func(*Context) error BeforeFunc is an action to execute before any subcommands are run, but after the context is ready if a non-nil error is returned, no subcommands are run @@ -471,8 +466,8 @@ type Command struct { ArgsUsage string // The category the command is part of Category string - // The function to call when checking for bash command completions - BashComplete BashCompleteFunc + // The function to call when checking for shell command completions + ShellComplete ShellCompleteFunc // An action to execute before any sub-subcommands are run, but after the context is ready // If a non-nil error is returned, no sub-subcommands are run Before BeforeFunc @@ -756,7 +751,7 @@ type Flag interface { implemented. var BashCompletionFlag Flag = &BoolFlag{ - Name: "generate-bash-completion", + Name: "generate-shell-completion", Hidden: true, } BashCompletionFlag enables bash-completion for all commands and subcommands @@ -999,6 +994,10 @@ type Serializer interface { } Serializer is used to circumvent the limitations of flag.FlagSet.Set +type ShellCompleteFunc func(*Context) + ShellCompleteFunc is an action to execute when the shell completion flag is + set + type SliceBase[T any, C any, VC ValueCreator[T, C]] struct { // Has unexported fields. }