1
1
package main
2
2
3
3
import (
4
- "github.com/docker/cli/cli/command/completion"
5
4
"github.com/docker/cli/cli/context/store"
6
5
"github.com/spf13/cobra"
7
6
)
@@ -10,18 +9,15 @@ type contextStoreProvider interface {
10
9
ContextStore () store.Store
11
10
}
12
11
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 ) {
15
14
names , _ := store .Names (dockerCLI .ContextStore ())
16
15
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
24
16
}
17
+ }
18
+
19
+ var logLevels = []string {"debug" , "info" , "warn" , "error" , "fatal" , "panic" }
25
20
26
- return nil
21
+ func completeLogLevels (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
22
+ return cobra .FixedCompletions (logLevels , cobra .ShellCompDirectiveNoFileComp )(nil , nil , "" )
27
23
}
0 commit comments