From 60987b8d7a9afd5f1d97fcb071d4d5baeb47ee54 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 4 Nov 2022 13:40:46 +0100 Subject: [PATCH] cli/command: DockerCli: keep reference to options for later use Store a reference to the options in the client, so that they are available for later use. Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index e32f8303c7..0cce3fa505 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -69,6 +69,7 @@ type Cli interface { // Instances of the client can be returned from NewDockerCli. type DockerCli struct { configFile *configfile.ConfigFile + options *cliflags.ClientOptions in *streams.In out *streams.Out err io.Writer @@ -222,17 +223,16 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize return errors.New("conflicting options: either specify --host or --context, not both") } + cli.options = opts cli.configFile = config.LoadDefaultConfigFile(cli.err) - - baseContextStore := store.New(config.ContextStoreDir(), cli.contextStoreConfig) + cli.currentContext = resolveContextName(cli.options, cli.configFile) cli.contextStore = &ContextStoreWithDefault{ - Store: baseContextStore, + Store: store.New(config.ContextStoreDir(), cli.contextStoreConfig), Resolver: func() (*DefaultContext, error) { - return ResolveDefaultContext(opts, cli.contextStoreConfig) + return ResolveDefaultContext(cli.options, cli.contextStoreConfig) }, } - cli.currentContext = resolveContextName(opts, cli.configFile) - cli.dockerEndpoint, err = resolveDockerEndpoint(cli.contextStore, cli.currentContext) + cli.dockerEndpoint, err = resolveDockerEndpoint(cli.contextStore, resolveContextName(opts, cli.configFile)) if err != nil { return errors.Wrap(err, "unable to resolve docker endpoint") }