Skip to content

Commit f9e4335

Browse files
committed
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 <github@gone.nl>
1 parent 2a9fd4a commit f9e4335

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

cli/command/secret/remove.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ package secret
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
6-
"strings"
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10-
"github.com/pkg/errors"
1110
"github.com/spf13/cobra"
1211
)
1312

1413
type removeOptions struct {
1514
names []string
1615
}
1716

18-
func newSecretRemoveCommand(dockerCli command.Cli) *cobra.Command {
17+
func newSecretRemoveCommand(dockerCLI command.Cli) *cobra.Command {
1918
return &cobra.Command{
2019
Use: "rm SECRET [SECRET...]",
2120
Aliases: []string{"remove"},
@@ -25,31 +24,24 @@ func newSecretRemoveCommand(dockerCli command.Cli) *cobra.Command {
2524
opts := removeOptions{
2625
names: args,
2726
}
28-
return runSecretRemove(cmd.Context(), dockerCli, opts)
27+
return runRemove(cmd.Context(), dockerCLI, opts)
2928
},
3029
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
31-
return completeNames(dockerCli)(cmd, args, toComplete)
30+
return completeNames(dockerCLI)(cmd, args, toComplete)
3231
},
3332
}
3433
}
3534

36-
func runSecretRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions) error {
37-
client := dockerCli.Client()
38-
39-
var errs []string
35+
func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions) error {
36+
apiClient := dockerCLI.Client()
4037

38+
var errs []error
4139
for _, name := range opts.names {
42-
if err := client.SecretRemove(ctx, name); err != nil {
43-
errs = append(errs, err.Error())
40+
if err := apiClient.SecretRemove(ctx, name); err != nil {
41+
errs = append(errs, err)
4442
continue
4543
}
46-
47-
fmt.Fprintln(dockerCli.Out(), name)
44+
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
4845
}
49-
50-
if len(errs) > 0 {
51-
return errors.Errorf("%s", strings.Join(errs, "\n"))
52-
}
53-
54-
return nil
46+
return errors.Join(errs...)
5547
}

0 commit comments

Comments
 (0)