mirror of https://github.com/docker/cli.git
cmd/docker: registerCompletionFuncForGlobalFlags: take store.Store as argument
Update this function to accept a smaller interface, as it doesn't need all of "CLI". Also return errors encountered during its operation (although the caller currently has no error return on its own). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c825db8a69
commit
0e37dd49f0
|
@ -1,27 +1,34 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
"github.com/docker/cli/cli/context/store"
|
"github.com/docker/cli/cli/context/store"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerCompletionFuncForGlobalFlags(dockerCli *command.DockerCli, cmd *cobra.Command) {
|
func registerCompletionFuncForGlobalFlags(contextStore store.Store, cmd *cobra.Command) error {
|
||||||
cmd.RegisterFlagCompletionFunc(
|
err := cmd.RegisterFlagCompletionFunc(
|
||||||
"context",
|
"context",
|
||||||
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
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 {
|
if err != nil {
|
||||||
return nil, cobra.ShellCompDirectiveError
|
return nil, cobra.ShellCompDirectiveError
|
||||||
}
|
}
|
||||||
return names, cobra.ShellCompDirectiveNoFileComp
|
return names, cobra.ShellCompDirectiveNoFileComp
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
cmd.RegisterFlagCompletionFunc(
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = cmd.RegisterFlagCompletionFunc(
|
||||||
"log-level",
|
"log-level",
|
||||||
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
values := []string{"debug", "info", "warn", "error", "fatal"}
|
values := []string{"debug", "info", "warn", "error", "fatal"}
|
||||||
return values, cobra.ShellCompDirectiveNoFileComp
|
return values, cobra.ShellCompDirectiveNoFileComp
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
|
||||||
cmd.SetErr(dockerCli.Err())
|
cmd.SetErr(dockerCli.Err())
|
||||||
|
|
||||||
opts, helpCmd = cli.SetupRootCommand(cmd)
|
opts, helpCmd = cli.SetupRootCommand(cmd)
|
||||||
registerCompletionFuncForGlobalFlags(dockerCli, cmd)
|
_ = registerCompletionFuncForGlobalFlags(dockerCli.ContextStore(), cmd)
|
||||||
cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
|
cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
|
||||||
setFlagErrorFunc(dockerCli, cmd)
|
setFlagErrorFunc(dockerCli, cmd)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue