From eda78e9cdc79e4ec2d886e0a75c0abe06dd5489e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 19 Oct 2024 12:07:51 +0200 Subject: [PATCH] cli/command: PromptUserForCredentials: move trimming where it's used - move trimming defaultUsername inside the if-branch, as it's the only location where the result of the trimmed username is use. - do the reverse for trimming argUser, because the result of trimming argUser is used outside of the if-branch (not just for the condition). putting it inside the condition makes it easy to assume the result is only used locally. Signed-off-by: Sebastiaan van Stijn --- cli/command/registry.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index b2696d7b1d..7749f9601a 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -123,9 +123,8 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword cli.SetIn(streams.NewIn(os.Stdin)) } - defaultUsername = strings.TrimSpace(defaultUsername) - - if argUser = strings.TrimSpace(argUser); argUser == "" { + argUser = strings.TrimSpace(argUser) + if argUser == "" { if serverAddress == registry.IndexServer { // if this is a default registry (docker hub), then display the following message. fmt.Fprintln(cli.Out(), "Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.") @@ -136,6 +135,7 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword } var prompt string + defaultUsername = strings.TrimSpace(defaultUsername) if defaultUsername == "" { prompt = "Username: " } else {