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.
@@ -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" {
+ // 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 && name != "default" {
+ if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil {
return err
}
- configValue := name
- if configValue == "default" {
- configValue = ""
+ configValue = name
}
dockerConfig := dockerCli.ConfigFile()
dockerConfig.CurrentContext = configValue
