mirror of
https://github.com/docker/compose.git
synced 2026-10-20 19:02:47 +00:00
Add multierror
docker/api/multierror wraps go-multierror from hashicorp with our default error formating
This commit is contained in:
parent
2d14bfeb38
commit
6486f199e2
6 changed files with 153 additions and 11 deletions
|
|
@ -33,10 +33,10 @@ import (
|
|||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/context/store"
|
||||
"github.com/docker/api/multierror"
|
||||
)
|
||||
|
||||
// ContextCommand manages contexts
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/client"
|
||||
"github.com/docker/api/multierror"
|
||||
)
|
||||
|
||||
type rmOpts struct {
|
||||
|
|
@ -23,26 +23,22 @@ func RmCommand() *cobra.Command {
|
|||
Short: "Remove containers",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var errs []string
|
||||
c, err := client.New(cmd.Context())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
var errs *multierror.Error
|
||||
for _, id := range args {
|
||||
err := c.ContainerService().Delete(cmd.Context(), id, opts.force)
|
||||
if err != nil {
|
||||
errs = append(errs, err.Error()+" "+id)
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
}
|
||||
fmt.Println(id)
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
}
|
||||
|
||||
return nil
|
||||
return errs.ErrorOrNil()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue