mirror of https://github.com/docker/cli.git
cli/command/context: minor cleanup in runList()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0cc3f688d6
commit
592d90cafa
|
@ -44,13 +44,16 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
|
||||||
if opts.format == "" {
|
if opts.format == "" {
|
||||||
opts.format = formatter.TableFormatKey
|
opts.format = formatter.TableFormatKey
|
||||||
}
|
}
|
||||||
curContext := dockerCli.CurrentContext()
|
|
||||||
contextMap, err := dockerCli.ContextStore().List()
|
contextMap, err := dockerCli.ContextStore().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var contexts []*formatter.ClientContext
|
var (
|
||||||
|
curContext = dockerCli.CurrentContext()
|
||||||
|
contexts []*formatter.ClientContext
|
||||||
|
)
|
||||||
for _, rawMeta := range contextMap {
|
for _, rawMeta := range contextMap {
|
||||||
|
isCurrent := rawMeta.Name == curContext
|
||||||
meta, err := command.GetDockerContext(rawMeta)
|
meta, err := command.GetDockerContext(rawMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -61,7 +64,7 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
|
||||||
}
|
}
|
||||||
desc := formatter.ClientContext{
|
desc := formatter.ClientContext{
|
||||||
Name: rawMeta.Name,
|
Name: rawMeta.Name,
|
||||||
Current: rawMeta.Name == curContext,
|
Current: isCurrent,
|
||||||
Description: meta.Description,
|
Description: meta.Description,
|
||||||
DockerEndpoint: dockerEndpoint.Host,
|
DockerEndpoint: dockerEndpoint.Host,
|
||||||
}
|
}
|
||||||
|
@ -74,7 +77,7 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if os.Getenv(client.EnvOverrideHost) != "" {
|
if os.Getenv(client.EnvOverrideHost) != "" {
|
||||||
fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
|
_, _ = fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
|
||||||
"To use a context, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost)
|
"To use a context, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue