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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-07-29 11:11:31 +02:00
parent 7963778e0a
commit cee286ff63
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 10 additions and 9 deletions

View File

@ -25,15 +25,16 @@ func newUseCommand(dockerCli command.Cli) *cobra.Command {
// RunUse set the current Docker context // RunUse set the current Docker context
func RunUse(dockerCli command.Cli, name string) error { func RunUse(dockerCli command.Cli, name string) error {
if err := store.ValidateContextName(name); err != nil && name != "default" { // configValue uses an empty string for "default"
return err var configValue string
} if name != command.DefaultContextName {
if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil && name != "default" { if err := store.ValidateContextName(name); err != nil {
return err return err
} }
configValue := name if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil {
if configValue == "default" { return err
configValue = "" }
configValue = name
} }
dockerConfig := dockerCli.ConfigFile() dockerConfig := dockerCli.ConfigFile()
dockerConfig.CurrentContext = configValue dockerConfig.CurrentContext = configValue