From d35b50c0c3392f05f58d4233e326dd4467ecd1cb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 3 Mar 2021 12:07:01 +0100 Subject: [PATCH 1/2] NewAPIClientFromFlags: rename variable to not collide with import Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 7e9ed3c8f5..103184d4de 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -271,17 +271,17 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize // NewAPIClientFromFlags creates a new APIClient from command line flags func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) { storeConfig := DefaultContextStoreConfig() - store := &ContextStoreWithDefault{ + contextStore := &ContextStoreWithDefault{ Store: store.New(cliconfig.ContextStoreDir(), storeConfig), Resolver: func() (*DefaultContext, error) { return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard) }, } - contextName, err := resolveContextName(opts, configFile, store) + contextName, err := resolveContextName(opts, configFile, contextStore) if err != nil { return nil, err } - endpoint, err := resolveDockerEndpoint(store, contextName) + endpoint, err := resolveDockerEndpoint(contextStore, contextName) if err != nil { return nil, errors.Wrap(err, "unable to resolve docker endpoint") } From cc08fc1af082597ff452e8c8cf411863705be7ba Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 3 Mar 2021 12:09:20 +0100 Subject: [PATCH 2/2] Implement WithDefaultContextStoreConfig() DockerCliOption Just a minor refactor to make this slightly cleaner Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 5 +++-- cli/command/cli_options.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 103184d4de..cfa43921b3 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -422,12 +422,13 @@ type ClientInfo struct { // It applies by default the standard streams, and the content trust from // environment. func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) { - cli := &DockerCli{} defaultOps := []DockerCliOption{ WithContentTrustFromEnv(), + WithDefaultContextStoreConfig(), } - cli.contextStoreConfig = DefaultContextStoreConfig() ops = append(defaultOps, ops...) + + cli := &DockerCli{} if err := cli.Apply(ops...); err != nil { return nil, err } diff --git a/cli/command/cli_options.go b/cli/command/cli_options.go index 290cae45c3..cd81794982 100644 --- a/cli/command/cli_options.go +++ b/cli/command/cli_options.go @@ -94,3 +94,11 @@ func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) return nil } } + +// WithDefaultContextStoreConfig configures the cli to use the default context store configuration. +func WithDefaultContextStoreConfig() DockerCliOption { + return func(cli *DockerCli) error { + cli.contextStoreConfig = DefaultContextStoreConfig() + return nil + } +}