Skip to content

Commit 90bc986

Browse files
committed
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 moby/moby@0452ff5 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 <[email protected]>
1 parent 3403f27 commit 90bc986

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

cli/cobra.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
pluginmanager "github.com/docker/cli/cli-plugins/manager"
1111
"github.com/docker/cli/cli/command"
12-
"github.com/docker/cli/cli/config"
1312
cliflags "github.com/docker/cli/cli/flags"
1413
"github.com/docker/docker/pkg/homedir"
1514
"github.com/docker/docker/registry"
@@ -24,10 +23,8 @@ import (
2423
// setupCommonRootCommand contains the setup common to
2524
// SetupRootCommand and SetupPluginRootCommand.
2625
func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet, *cobra.Command) {
27-
opts := cliflags.NewClientOptions()
2826
flags := rootCmd.Flags()
29-
30-
flags.StringVar(&opts.ConfigDir, "config", config.Dir(), "Location of client config files")
27+
opts := cliflags.NewClientOptions()
3128
opts.InstallFlags(flags)
3229

3330
cobra.AddTemplateFunc("add", func(a, b int) int { return a + b })

cli/flags/options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ func NewClientOptions() *ClientOptions {
7373

7474
// InstallFlags adds flags for the common options on the FlagSet
7575
func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
76+
configDir := config.Dir()
7677
if dockerCertPath == "" {
77-
dockerCertPath = config.Dir()
78+
dockerCertPath = configDir
7879
}
7980

81+
flags.StringVar(&o.ConfigDir, "config", configDir, "Location of client config files")
8082
flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode")
8183
flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug", "info", "warn", "error", "fatal")`)
8284
flags.BoolVar(&o.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify")
@@ -95,8 +97,7 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
9597
// opts.ValidateHost is not used here, so as to allow connection helpers
9698
hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, nil)
9799
flags.VarP(hostOpt, "host", "H", "Daemon socket to connect to")
98-
flags.StringVarP(&o.Context, "context", "c", "",
99-
`Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`)
100+
flags.StringVarP(&o.Context, "context", "c", "", `Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`)
100101
}
101102

102103
// SetDefaultOptions sets default values for options after flag parsing is

0 commit comments

Comments
 (0)