From 3cad05fbf9b7e3baf660868476bd1d8d4192f1bc Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 28 Jun 2023 15:40:42 +0200 Subject: [PATCH] cli: move "config" flag to cli/flags/ClientOptions.InstallFlags() This flag was kept separate from the other flags, because at the time, the CLI code and Daemon code still used the same codebase, and shared some parts. This option only applied to the `docker` CLI, and thus was kept separate when migrating to Cobra in https://github.com/moby/moby/commit/0452ff5a4dd1b8fba707235d6f12a4038208f34b Now that this code is only used for the CLI (and plugins), we can move this flag together with the other flags. Signed-off-by: Sebastiaan van Stijn --- cli/cobra.go | 5 +---- cli/flags/options.go | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/cobra.go b/cli/cobra.go index c6ce31dccf..178e820fd0 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -9,7 +9,6 @@ import ( pluginmanager "github.com/docker/cli/cli-plugins/manager" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/config" cliflags "github.com/docker/cli/cli/flags" "github.com/docker/docker/pkg/homedir" "github.com/docker/docker/registry" @@ -24,10 +23,8 @@ import ( // setupCommonRootCommand contains the setup common to // SetupRootCommand and SetupPluginRootCommand. func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet, *cobra.Command) { - opts := cliflags.NewClientOptions() flags := rootCmd.Flags() - - flags.StringVar(&opts.ConfigDir, "config", config.Dir(), "Location of client config files") + opts := cliflags.NewClientOptions() opts.InstallFlags(flags) cobra.AddTemplateFunc("add", func(a, b int) int { return a + b }) diff --git a/cli/flags/options.go b/cli/flags/options.go index 6c21b74f8d..5a6df9c889 100644 --- a/cli/flags/options.go +++ b/cli/flags/options.go @@ -73,10 +73,12 @@ func NewClientOptions() *ClientOptions { // InstallFlags adds flags for the common options on the FlagSet func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) { + configDir := config.Dir() if dockerCertPath == "" { - dockerCertPath = config.Dir() + dockerCertPath = configDir } + flags.StringVar(&o.ConfigDir, "config", configDir, "Location of client config files") flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode") flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug", "info", "warn", "error", "fatal")`) flags.BoolVar(&o.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify")