@@ -2,6 +2,7 @@ package container
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "strings"
78
@@ -10,7 +11,6 @@ import (
1011 "github.com/docker/cli/cli/command/completion"
1112 "github.com/docker/docker/api/types/container"
1213 "github.com/docker/docker/errdefs"
13- "github.com/pkg/errors"
1414 "github.com/spf13/cobra"
1515)
1616
@@ -50,33 +50,31 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
5050 return cmd
5151}
5252
53- func runRm (ctx context.Context , dockerCli command.Cli , opts * rmOptions ) error {
54- var errs [] string
53+ func runRm (ctx context.Context , dockerCLI command.Cli , opts * rmOptions ) error {
54+ apiClient := dockerCLI . Client ()
5555 errChan := parallelOperation (ctx , opts .containers , func (ctx context.Context , ctrID string ) error {
5656 ctrID = strings .Trim (ctrID , "/" )
5757 if ctrID == "" {
58- return errors .New ("Container name cannot be empty" )
58+ return errors .New ("container name cannot be empty" )
5959 }
60- return dockerCli . Client () .ContainerRemove (ctx , ctrID , container.RemoveOptions {
60+ return apiClient .ContainerRemove (ctx , ctrID , container.RemoveOptions {
6161 RemoveVolumes : opts .rmVolumes ,
6262 RemoveLinks : opts .rmLink ,
6363 Force : opts .force ,
6464 })
6565 })
6666
67+ var errs []error
6768 for _ , name := range opts .containers {
6869 if err := <- errChan ; err != nil {
6970 if opts .force && errdefs .IsNotFound (err ) {
70- fmt .Fprintln (dockerCli .Err (), err )
71+ _ , _ = fmt .Fprintln (dockerCLI .Err (), err )
7172 continue
7273 }
73- errs = append (errs , err . Error () )
74+ errs = append (errs , err )
7475 continue
7576 }
76- fmt .Fprintln (dockerCli .Out (), name )
77+ _ , _ = fmt .Fprintln (dockerCLI .Out (), name )
7778 }
78- if len (errs ) > 0 {
79- return errors .New (strings .Join (errs , "\n " ))
80- }
81- return nil
79+ return errors .Join (errs ... )
8280}
0 commit comments