From f9e4335564ed8edc1f8213affa8c01698ffb7f86 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Feb 2025 19:33:58 +0100 Subject: [PATCH] cli/command/secret: use errors.Join - Use stdlib multi-errors instead of creating our own - use apiClient instead of client for the API client to prevent shadowing imports. - use dockerCLI with Go's standard camelCase casing. - rename runSecretRemove to runRemove to align with other commands Signed-off-by: Sebastiaan van Stijn --- cli/command/secret/remove.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/cli/command/secret/remove.go b/cli/command/secret/remove.go index e51d03d345..2a2764a8e3 100644 --- a/cli/command/secret/remove.go +++ b/cli/command/secret/remove.go @@ -2,12 +2,11 @@ package secret import ( "context" + "errors" "fmt" - "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -15,7 +14,7 @@ type removeOptions struct { names []string } -func newSecretRemoveCommand(dockerCli command.Cli) *cobra.Command { +func newSecretRemoveCommand(dockerCLI command.Cli) *cobra.Command { return &cobra.Command{ Use: "rm SECRET [SECRET...]", Aliases: []string{"remove"}, @@ -25,31 +24,24 @@ func newSecretRemoveCommand(dockerCli command.Cli) *cobra.Command { opts := removeOptions{ names: args, } - return runSecretRemove(cmd.Context(), dockerCli, opts) + return runRemove(cmd.Context(), dockerCLI, opts) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return completeNames(dockerCli)(cmd, args, toComplete) + return completeNames(dockerCLI)(cmd, args, toComplete) }, } } -func runSecretRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions) error { - client := dockerCli.Client() - - var errs []string +func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions) error { + apiClient := dockerCLI.Client() + var errs []error for _, name := range opts.names { - if err := client.SecretRemove(ctx, name); err != nil { - errs = append(errs, err.Error()) + if err := apiClient.SecretRemove(ctx, name); err != nil { + errs = append(errs, err) continue } - - fmt.Fprintln(dockerCli.Out(), name) + _, _ = fmt.Fprintln(dockerCLI.Out(), name) } - - if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil + return errors.Join(errs...) }