cli/command/container: 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:17:50 +01:00
parent 791e06b435
commit 150f27b68c
8 changed files with 67 additions and 84 deletions

View File

@ -2,13 +2,12 @@ package container
import (
"context"
"errors"
"fmt"
"strings"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -37,20 +36,19 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error {
var errs []string
func runWait(ctx context.Context, dockerCLI command.Cli, opts *waitOptions) error {
apiClient := dockerCLI.Client()
var errs []error
for _, ctr := range opts.containers {
resultC, errC := dockerCli.Client().ContainerWait(ctx, ctr, "")
resultC, errC := apiClient.ContainerWait(ctx, ctr, "")
select {
case result := <-resultC:
_, _ = fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
_, _ = fmt.Fprintf(dockerCLI.Out(), "%d\n", result.StatusCode)
case err := <-errC:
errs = append(errs, err.Error())
errs = append(errs, err)
}
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
}
return nil
return errors.Join(errs...)
}