diff --git a/command.go b/command.go index d108f856..36817587 100644 --- a/command.go +++ b/command.go @@ -94,7 +94,7 @@ type Command struct { // ArgAliases is List of aliases for ValidArgs. // These are not suggested to the user in the shell completion, // but accepted if entered manually. - ArgAliases []CompletionChoice + ArgAliases []string // BashCompletionFunction is custom bash functions used by the legacy bash autocompletion generator. // For portability with other shells, it is recommended to instead use ValidArgsFunction diff --git a/completions.go b/completions.go index 044a83e7..240d4fc1 100644 --- a/completions.go +++ b/completions.go @@ -120,20 +120,20 @@ type CompletionOptions struct { // CompletionChoice is a string that can be used for completions // // two formats are supported: -// - the name of the flag -// - the name of the flag with its description (separated by a tab) +// - the completion choice +// - the completion choice with a textual description (separated by a TAB). // -// [CompletionChoiceWithDescription] can be used to create a completion string with a description using the TAB separator. +// [CompletionChoiceWithDescription] can be used to create a completion string with a textual description. // // Note: Go type alias is used to provide a more descriptive name in the documentation, but any string can be used. type CompletionChoice = string // CompletionFunc is a function that provides completion results. -type CompletionFunc func(cmd *Command, args []CompletionChoice, toComplete string) ([]string, ShellCompDirective) +type CompletionFunc func(cmd *Command, args []string, toComplete string) ([]CompletionChoice, ShellCompDirective) -// CompletionChoiceWithDescription returns a CompletionChoice with a description -func CompletionChoiceWithDescription(name, desc string) CompletionChoice { - return name + "\t" + desc +// CompletionChoiceWithDescription returns a [CompletionChoice] with a description by using the TAB delimited format. +func CompletionChoiceWithDescription(choice string, description string) CompletionChoice { + return choice + "\t" + description } // NoFileCompletions can be used to disable file completion for commands that should @@ -141,7 +141,7 @@ func CompletionChoiceWithDescription(name, desc string) CompletionChoice { // // This method satisfies [CompletionFunc]. // It can be used with [Command.RegisterFlagCompletionFunc] and for [Command.ValidArgsFunction]. -func NoFileCompletions(cmd *Command, args []CompletionChoice, toComplete string) ([]string, ShellCompDirective) { +func NoFileCompletions(cmd *Command, args []string, toComplete string) ([]CompletionChoice, ShellCompDirective) { return nil, ShellCompDirectiveNoFileComp } @@ -151,7 +151,7 @@ func NoFileCompletions(cmd *Command, args []CompletionChoice, toComplete string) // This method returns a function that satisfies [CompletionFunc] // It can be used with [Command.RegisterFlagCompletionFunc] and for [Command.ValidArgsFunction]. func FixedCompletions(choices []CompletionChoice, directive ShellCompDirective) CompletionFunc { - return func(cmd *Command, args []CompletionChoice, toComplete string) ([]string, ShellCompDirective) { + return func(cmd *Command, args []string, toComplete string) ([]CompletionChoice, ShellCompDirective) { return choices, directive } }