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

Commit 8d755ae

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 80c1b22 commit 8d755ae

File tree

4 files changed

+27
-178
lines changed

4 files changed

+27
-178
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ 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"
2729
"github.com/docker/api/containers"
2830
"github.com/docker/api/errdefs"
29-
"github.com/docker/api/multierror"
3031
)
3132

3233
type rmOpts struct {
@@ -75,6 +76,16 @@ func runRm(ctx context.Context, args []string, opts rmOpts) error {
7576

7677
fmt.Println(id)
7778
}
78-
79+
if errs != nil {
80+
errs.ErrorFormat = formatErrors
81+
}
7982
return errs.ErrorOrNil()
8083
}
84+
85+
func formatErrors(errs []error) string {
86+
messages := make([]string, len(errs))
87+
for i, err := range errs {
88+
messages[i] = "Error: "+err.Error()
89+
}
90+
return strings.Join(messages, "\n")
91+
}

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)