MCPcopy Index your code
hub / github.com/docker/cli / resolveContextName

Function resolveContextName

cli/command/cli.go:439–457  ·  view source on GitHub ↗

CurrentContext returns the current context name, based on flags, environment variables and the cli configuration file. It does not validate if the given context exists or if it's valid; errors may occur when trying to use it. Refer to [DockerCli.CurrentContext] above for further details.

(opts *cliflags.ClientOptions, cfg *configfile.ConfigFile)

Source from the content-addressed store, hash-verified

437//
438// Refer to [DockerCli.CurrentContext] above for further details.
439func resolveContextName(opts *cliflags.ClientOptions, cfg *configfile.ConfigFile) string {
440 if opts != nil && opts.Context != "" {
441 return opts.Context
442 }
443 if opts != nil && len(opts.Hosts) > 0 {
444 return DefaultContextName
445 }
446 if os.Getenv(client.EnvOverrideHost) != "" {
447 return DefaultContextName
448 }
449 if ctxName := os.Getenv(EnvOverrideContext); ctxName != "" {
450 return ctxName
451 }
452 if cfg != nil && cfg.CurrentContext != "" {
453 // We don't validate if this context exists: errors may occur when trying to use it.
454 return cfg.CurrentContext
455 }
456 return DefaultContextName
457}
458
459// DockerEndpoint returns the current docker endpoint
460func (cli *DockerCli) DockerEndpoint() docker.Endpoint {

Callers 2

InitializeMethod · 0.85
NewAPIClientFromFlagsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…