11package main
22
33import (
4- "github.com/docker/cli/cli/command/completion"
54 "github.com/docker/cli/cli/context/store"
65 "github.com/spf13/cobra"
76)
@@ -10,18 +9,15 @@ type contextStoreProvider interface {
109 ContextStore () store.Store
1110}
1211
13- func registerCompletionFuncForGlobalFlags (dockerCLI contextStoreProvider , cmd * cobra.Command ) error {
14- err := cmd . RegisterFlagCompletionFunc ( "context" , func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
12+ func completeContextNames (dockerCLI contextStoreProvider ) func ( * cobra.Command , [] string , string ) ([] string , cobra. ShellCompDirective ) {
13+ return func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
1514 names , _ := store .Names (dockerCLI .ContextStore ())
1615 return names , cobra .ShellCompDirectiveNoFileComp
17- })
18- if err != nil {
19- return err
20- }
21- err = cmd .RegisterFlagCompletionFunc ("log-level" , completion .FromList ("debug" , "info" , "warn" , "error" , "fatal" ))
22- if err != nil {
23- return err
2416 }
17+ }
18+
19+ var logLevels = []string {"debug" , "info" , "warn" , "error" , "fatal" , "panic" }
2520
26- return nil
21+ func completeLogLevels (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
22+ return cobra .FixedCompletions (logLevels , cobra .ShellCompDirectiveNoFileComp )(nil , nil , "" )
2723}
0 commit comments