2022-03-30 09:27:25 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-07-05 08:15:29 -04:00
|
|
|
"github.com/docker/cli/cli/command/completion"
|
2022-03-30 09:27:25 -04:00
|
|
|
"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
|
|
|
|
}
|
2024-07-05 08:15:29 -04:00
|
|
|
err = cmd.RegisterFlagCompletionFunc("log-level", completion.FromList("debug", "info", "warn", "error", "fatal"))
|
2024-01-11 12:17:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-03-30 09:27:25 -04:00
|
|
|
}
|