mirror of https://github.com/docker/cli.git
Merge pull request #2992 from thaJeztah/refactor_default_context_store_config
Implement WithDefaultContextStoreConfig() DockerCliOption
This commit is contained in:
commit
c61452c580
|
@ -271,17 +271,17 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
|
||||||
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
// NewAPIClientFromFlags creates a new APIClient from command line flags
|
||||||
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
|
||||||
storeConfig := DefaultContextStoreConfig()
|
storeConfig := DefaultContextStoreConfig()
|
||||||
store := &ContextStoreWithDefault{
|
contextStore := &ContextStoreWithDefault{
|
||||||
Store: store.New(cliconfig.ContextStoreDir(), storeConfig),
|
Store: store.New(cliconfig.ContextStoreDir(), storeConfig),
|
||||||
Resolver: func() (*DefaultContext, error) {
|
Resolver: func() (*DefaultContext, error) {
|
||||||
return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard)
|
return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
contextName, err := resolveContextName(opts, configFile, store)
|
contextName, err := resolveContextName(opts, configFile, contextStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
endpoint, err := resolveDockerEndpoint(store, contextName)
|
endpoint, err := resolveDockerEndpoint(contextStore, contextName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "unable to resolve docker endpoint")
|
return nil, errors.Wrap(err, "unable to resolve docker endpoint")
|
||||||
}
|
}
|
||||||
|
@ -422,12 +422,13 @@ type ClientInfo struct {
|
||||||
// It applies by default the standard streams, and the content trust from
|
// It applies by default the standard streams, and the content trust from
|
||||||
// environment.
|
// environment.
|
||||||
func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) {
|
func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) {
|
||||||
cli := &DockerCli{}
|
|
||||||
defaultOps := []DockerCliOption{
|
defaultOps := []DockerCliOption{
|
||||||
WithContentTrustFromEnv(),
|
WithContentTrustFromEnv(),
|
||||||
|
WithDefaultContextStoreConfig(),
|
||||||
}
|
}
|
||||||
cli.contextStoreConfig = DefaultContextStoreConfig()
|
|
||||||
ops = append(defaultOps, ops...)
|
ops = append(defaultOps, ops...)
|
||||||
|
|
||||||
|
cli := &DockerCli{}
|
||||||
if err := cli.Apply(ops...); err != nil {
|
if err := cli.Apply(ops...); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,3 +94,11 @@ func WithContextEndpointType(endpointName string, endpointType store.TypeGetter)
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue