-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
kind/supportQuestions, supporting users, etc.Questions, supporting users, etc.
Description
I feel like I'm missing something with autocomplete suggestions. I want it to suggest the names "steve" and "john" (for the command below) but all it does is suggest files in the directory. Am I missing something? I feel like I've tried everything - and I can't get it to suggest a single thing.
var HelloCmd = &cobra.Command{
Use: "hello <name>",
Short: "Say hello to someone",
Long: `Say hello to someone`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(args)
fmt.Println("hello " + args[0])
cmd.Help()
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return []string{"steve", "john"}, cobra.ShellCompDirectiveNoFileComp
},
}
On mac zsh I run go build .
followed by ./program hello s[TAB]
or ./program hello j[TAB]
. If I type ./program hello [TAB]
it suggests the files in the directory. Any help is greatly appreciated.
Metadata
Metadata
Assignees
Labels
kind/supportQuestions, supporting users, etc.Questions, supporting users, etc.