cli/command/service: use errors.Join

Use stdlib multi-errors instead of creating our own

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-02-03 19:36:59 +01:00
parent f9e4335564
commit f1193effc0
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -2,12 +2,11 @@ package service
import (
"context"
"errors"
"fmt"
"strings"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -32,17 +31,13 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
func runRemove(ctx context.Context, dockerCLI command.Cli, serviceIDs []string) error {
apiClient := dockerCLI.Client()
var errs []string
var errs []error
for _, id := range serviceIDs {
err := apiClient.ServiceRemove(ctx, id)
if err != nil {
errs = append(errs, err.Error())
if err := apiClient.ServiceRemove(ctx, id); err != nil {
errs = append(errs, err)
continue
}
_, _ = fmt.Fprintln(dockerCLI.Out(), id)
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
}
return nil
return errors.Join(errs...)
}