2022-03-30 09:27:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/cli/cli/context/store"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2024-01-11 12:17:47 -05:00
|
|
|
func registerCompletionFuncForGlobalFlags(contextStore store.Store, cmd *cobra.Command) error {
|
|
|
|
err := cmd.RegisterFlagCompletionFunc(
|
2022-03-30 09:27:25 -04:00
|
|
|
"context",
|
|
|
|
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
2024-01-11 12:17:47 -05:00
|
|
|
names, err := store.Names(contextStore)
|
2022-03-30 09:27:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, cobra.ShellCompDirectiveError
|
|
|
|
}
|
|
|
|
return names, cobra.ShellCompDirectiveNoFileComp
|
|
|
|
},
|
|
|
|
)
|
2024-01-11 12:17:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = cmd.RegisterFlagCompletionFunc(
|
2022-03-30 09:27:25 -04:00
|
|
|
"log-level",
|
|
|
|
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
values := []string{"debug", "info", "warn", "error", "fatal"}
|
|
|
|
return values, cobra.ShellCompDirectiveNoFileComp
|
|
|
|
},
|
|
|
|
)
|
2024-01-11 12:17:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-03-30 09:27:25 -04:00
|
|
|
}
|