github.com/panekj/cli@v0.0.0-20230304125325-467dd2f3797e/cmd/docker/completions.go (about) 1 package main 2 3 import ( 4 "github.com/docker/cli/cli/command" 5 "github.com/docker/cli/cli/context/store" 6 "github.com/spf13/cobra" 7 ) 8 9 func registerCompletionFuncForGlobalFlags(dockerCli *command.DockerCli, cmd *cobra.Command) { 10 cmd.RegisterFlagCompletionFunc( 11 "context", 12 func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 13 names, err := store.Names(dockerCli.ContextStore()) 14 if err != nil { 15 return nil, cobra.ShellCompDirectiveError 16 } 17 return names, cobra.ShellCompDirectiveNoFileComp 18 }, 19 ) 20 cmd.RegisterFlagCompletionFunc( 21 "log-level", 22 func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 23 values := []string{"debug", "info", "warn", "error", "fatal"} 24 return values, cobra.ShellCompDirectiveNoFileComp 25 }, 26 ) 27 }