Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 15ca0e7

Browse files
committed
Remove custom multierrors package
The hashicorp/go-multierror package provides functionality to do this. Replacing the custom package in favor of those (at the cost of some small duplication). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4464bb5 commit 15ca0e7

File tree

4 files changed

+28
-180
lines changed

4 files changed

+28
-180
lines changed

cli/cmd/context/rm.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"strings"
2324

25+
"github.com/hashicorp/go-multierror"
2426
"github.com/spf13/cobra"
2527

2628
apicontext "github.com/docker/api/context"
2729
"github.com/docker/api/context/store"
28-
"github.com/docker/api/multierror"
2930
)
3031

3132
type removeOpts struct {
@@ -56,8 +57,7 @@ func runRemove(ctx context.Context, args []string, force bool) error {
5657
for _, contextName := range args {
5758
if currentContext == contextName {
5859
if force {
59-
err := runUse(ctx, "default")
60-
if err != nil {
60+
if err := runUse(ctx, "default"); err != nil {
6161
errs = multierror.Append(errs, errors.New("cannot delete current context"))
6262
} else {
6363
errs = removeContext(s, contextName, errs)
@@ -69,9 +69,20 @@ func runRemove(ctx context.Context, args []string, force bool) error {
6969
errs = removeContext(s, contextName, errs)
7070
}
7171
}
72+
if errs != nil {
73+
errs.ErrorFormat = formatErrors
74+
}
7275
return errs.ErrorOrNil()
7376
}
7477

78+
func formatErrors(errs []error) string {
79+
messages := make([]string, len(errs))
80+
for i, err := range errs {
81+
messages[i] = "Error: "+err.Error()
82+
}
83+
return strings.Join(messages, "\n")
84+
}
85+
7586
func removeContext(s store.Store, n string, errs *multierror.Error) *multierror.Error {
7687
if err := s.Remove(n); err != nil {
7788
errs = multierror.Append(errs, err)

cli/cmd/rm.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ package cmd
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

24+
"github.com/hashicorp/go-multierror"
2325
"github.com/pkg/errors"
2426
"github.com/spf13/cobra"
2527

2628
"github.com/docker/api/client"
27-
"github.com/docker/api/multierror"
2829
)
2930

3031
type rmOpts struct {
@@ -57,13 +58,22 @@ func runRm(ctx context.Context, args []string, opts rmOpts) error {
5758

5859
var errs *multierror.Error
5960
for _, id := range args {
60-
err := c.ContainerService().Delete(ctx, id, opts.force)
61-
if err != nil {
61+
if err := c.ContainerService().Delete(ctx, id, opts.force); err != nil {
6262
errs = multierror.Append(errs, err)
6363
continue
6464
}
6565
fmt.Println(id)
6666
}
67-
67+
if errs != nil {
68+
errs.ErrorFormat = formatErrors
69+
}
6870
return errs.ErrorOrNil()
6971
}
72+
73+
func formatErrors(errs []error) string {
74+
messages := make([]string, len(errs))
75+
for i, err := range errs {
76+
messages[i] = "Error: "+err.Error()
77+
}
78+
return strings.Join(messages, "\n")
79+
}

multierror/multierror.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

multierror/multierror_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)