Merge pull request #4778 from thaJeztah/cmd_docker_smaller_interface

cmd/docker: registerCompletionFuncForGlobalFlags: take store.Store as argument
This commit is contained in:
Sebastiaan van Stijn 2024-01-11 22:50:47 +01:00 committed by GitHub
commit 859154b94c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -1,27 +1,34 @@
package main
import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/context/store"
"github.com/spf13/cobra"
)
func registerCompletionFuncForGlobalFlags(dockerCli *command.DockerCli, cmd *cobra.Command) {
cmd.RegisterFlagCompletionFunc(
func registerCompletionFuncForGlobalFlags(contextStore store.Store, cmd *cobra.Command) error {
err := cmd.RegisterFlagCompletionFunc(
"context",
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
names, err := store.Names(dockerCli.ContextStore())
names, err := store.Names(contextStore)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
return names, cobra.ShellCompDirectiveNoFileComp
},
)
cmd.RegisterFlagCompletionFunc(
if err != nil {
return err
}
err = cmd.RegisterFlagCompletionFunc(
"log-level",
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
values := []string{"debug", "info", "warn", "error", "fatal"}
return values, cobra.ShellCompDirectiveNoFileComp
},
)
if err != nil {
return err
}
return nil
}

View File

@ -84,7 +84,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
cmd.SetErr(dockerCli.Err())
opts, helpCmd = cli.SetupRootCommand(cmd)
registerCompletionFuncForGlobalFlags(dockerCli, cmd)
_ = registerCompletionFuncForGlobalFlags(dockerCli.ContextStore(), cmd)
cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
setFlagErrorFunc(dockerCli, cmd)