From cee286ff63926d21c0474e206f5d33ed74d553cd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 29 Jul 2022 11:11:31 +0200 Subject: [PATCH] context use: skip validation for "default" context This code was handling validation and parsing, only to discard the results if it was the default context. Signed-off-by: Sebastiaan van Stijn --- cli/command/context/use.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/command/context/use.go b/cli/command/context/use.go index 29d157a377..cba4f92dad 100644 --- a/cli/command/context/use.go +++ b/cli/command/context/use.go @@ -25,15 +25,16 @@ func newUseCommand(dockerCli command.Cli) *cobra.Command { // RunUse set the current Docker context func RunUse(dockerCli command.Cli, name string) error { - if err := store.ValidateContextName(name); err != nil && name != "default" { - return err - } - if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil && name != "default" { - return err - } - configValue := name - if configValue == "default" { - configValue = "" + // configValue uses an empty string for "default" + var configValue string + if name != command.DefaultContextName { + if err := store.ValidateContextName(name); err != nil { + return err + } + if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil { + return err + } + configValue = name } dockerConfig := dockerCli.ConfigFile() dockerConfig.CurrentContext = configValue