cli/command/context: minor cleanup in runList()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-04 14:07:20 +01:00
parent 0cc3f688d6
commit 592d90cafa
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 7 additions and 4 deletions

View File

@ -44,13 +44,16 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
if opts.format == "" {
opts.format = formatter.TableFormatKey
}
curContext := dockerCli.CurrentContext()
contextMap, err := dockerCli.ContextStore().List()
if err != nil {
return err
}
var contexts []*formatter.ClientContext
var (
curContext = dockerCli.CurrentContext()
contexts []*formatter.ClientContext
)
for _, rawMeta := range contextMap {
isCurrent := rawMeta.Name == curContext
meta, err := command.GetDockerContext(rawMeta)
if err != nil {
return err
@ -61,7 +64,7 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
}
desc := formatter.ClientContext{
Name: rawMeta.Name,
Current: rawMeta.Name == curContext,
Current: isCurrent,
Description: meta.Description,
DockerEndpoint: dockerEndpoint.Host,
}
@ -74,7 +77,7 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
return err
}
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)
}
return nil