1
0
Fork 0
mirror of https://github.com/spf13/cobra synced 2025-04-07 15:29:16 +00:00

Apply code review feedback

Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com>
Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
This commit is contained in:
ccoVeille 2025-02-08 21:08:11 +01:00
parent f80a6ab97a
commit 7b78b0536a
No known key found for this signature in database
2 changed files with 10 additions and 10 deletions

View file

@ -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

View file

@ -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
}
}