Skip to content

Commit 016dbef

Browse files
committed
cli/command/registry: minor cleanups: use Println, rename vars
- use Println to print newline instead of custom format - use dockerCLI with Go's standard camelCase casing. - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 53aed61 commit 016dbef

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

cli/command/registry/login.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ func runLogin(ctx context.Context, dockerCli command.Cli, opts loginOptions) err
119119
return nil
120120
}
121121

122-
func loginWithStoredCredentials(ctx context.Context, dockerCli command.Cli, authConfig registrytypes.AuthConfig) (msg string, _ error) {
123-
_, _ = fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n")
124-
response, err := dockerCli.Client().RegistryLogin(ctx, authConfig)
122+
func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, authConfig registrytypes.AuthConfig) (msg string, _ error) {
123+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Authenticating with existing credentials...")
124+
response, err := dockerCLI.Client().RegistryLogin(ctx, authConfig)
125125
if err != nil {
126126
if errdefs.IsUnauthorized(err) {
127-
_, _ = fmt.Fprintf(dockerCli.Err(), "Stored credentials invalid or expired\n")
127+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Stored credentials invalid or expired")
128128
} else {
129-
_, _ = fmt.Fprintf(dockerCli.Err(), "Login did not succeed, error: %s\n", err)
129+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Login did not succeed, error:", err)
130130
}
131131
}
132132

@@ -135,7 +135,7 @@ func loginWithStoredCredentials(ctx context.Context, dockerCli command.Cli, auth
135135
authConfig.IdentityToken = response.IdentityToken
136136
}
137137

138-
if err := storeCredentials(dockerCli.ConfigFile(), authConfig); err != nil {
138+
if err := storeCredentials(dockerCLI.ConfigFile(), authConfig); err != nil {
139139
return "", err
140140
}
141141

cli/command/registry/logout.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
3535
return cmd
3636
}
3737

38-
func runLogout(ctx context.Context, dockerCli command.Cli, serverAddress string) error {
38+
func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error {
3939
var isDefaultRegistry bool
4040

4141
if serverAddress == "" {
@@ -55,25 +55,25 @@ func runLogout(ctx context.Context, dockerCli command.Cli, serverAddress string)
5555
}
5656

5757
if isDefaultRegistry {
58-
store := dockerCli.ConfigFile().GetCredentialsStore(registry.IndexServer)
58+
store := dockerCLI.ConfigFile().GetCredentialsStore(registry.IndexServer)
5959
if err := manager.NewManager(store).Logout(ctx); err != nil {
60-
fmt.Fprintf(dockerCli.Err(), "WARNING: %v\n", err)
60+
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", err)
6161
}
6262
}
6363

64-
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
64+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Removing login credentials for", hostnameAddress)
6565
errs := make(map[string]error)
6666
for _, r := range regsToLogout {
67-
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
67+
if err := dockerCLI.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
6868
errs[r] = err
6969
}
7070
}
7171

7272
// if at least one removal succeeded, report success. Otherwise report errors
7373
if len(errs) == len(regsToLogout) {
74-
fmt.Fprintln(dockerCli.Err(), "WARNING: could not erase credentials:")
74+
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING: could not erase credentials:")
7575
for k, v := range errs {
76-
fmt.Fprintf(dockerCli.Err(), "%s: %s\n", k, v)
76+
_, _ = fmt.Fprintf(dockerCLI.Err(), "%s: %s\n", k, v)
7777
}
7878
}
7979

0 commit comments

Comments
 (0)