diff --git a/cli/command/cli.go b/cli/command/cli.go index fc557635c4..a8711de70c 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -16,6 +16,7 @@ import ( "github.com/docker/cli/cli/context/docker" kubcontext "github.com/docker/cli/cli/context/kubernetes" "github.com/docker/cli/cli/context/store" + "github.com/docker/cli/cli/debug" cliflags "github.com/docker/cli/cli/flags" manifeststore "github.com/docker/cli/cli/manifest/store" registryclient "github.com/docker/cli/cli/registry/client" @@ -177,6 +178,16 @@ func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.Registry // Initialize the dockerCli runs initialization that must happen after command // line flags are parsed. func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error { + cliflags.SetLogLevel(opts.Common.LogLevel) + + if opts.ConfigDir != "" { + cliconfig.SetDir(opts.ConfigDir) + } + + if opts.Common.Debug { + debug.Enable() + } + cli.configFile = cliconfig.LoadDefaultConfigFile(cli.err) var err error cli.contextStore = store.New(cliconfig.ContextStoreDir(), cli.contextStoreConfig) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 5909953be3..b16b3ec194 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -10,7 +10,6 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/commands" cliconfig "github.com/docker/cli/cli/config" - "github.com/docker/cli/cli/debug" cliflags "github.com/docker/cli/cli/flags" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" @@ -36,7 +35,6 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // flags must be the top-level command flags, not cmd.Flags() opts.Common.SetDefaultOptions(flags) - dockerPreRun(opts) if err := dockerCli.Initialize(opts); err != nil { return err } @@ -144,7 +142,6 @@ func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opt // when using --help, PersistentPreRun is not called, so initialization is needed. // flags must be the top-level command flags, not cmd.Flags() opts.Common.SetDefaultOptions(flags) - dockerPreRun(opts) return dockerCli.Initialize(opts) } @@ -193,18 +190,6 @@ func main() { } } -func dockerPreRun(opts *cliflags.ClientOptions) { - cliflags.SetLogLevel(opts.Common.LogLevel) - - if opts.ConfigDir != "" { - cliconfig.SetDir(opts.ConfigDir) - } - - if opts.Common.Debug { - debug.Enable() - } -} - type versionDetails interface { Client() client.APIClient ClientInfo() command.ClientInfo