Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cli/cmd/context/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/spf13/cobra"

apicontext "github.com/docker/api/context"
"github.com/docker/api/context/store"
"github.com/docker/api/multierror"
)

type removeOpts struct {
Expand Down Expand Up @@ -56,8 +57,7 @@ func runRemove(ctx context.Context, args []string, force bool) error {
for _, contextName := range args {
if currentContext == contextName {
if force {
err := runUse(ctx, "default")
if err != nil {
if err := runUse(ctx, "default"); err != nil {
errs = multierror.Append(errs, errors.New("cannot delete current context"))
} else {
errs = removeContext(s, contextName, errs)
Expand All @@ -69,9 +69,20 @@ func runRemove(ctx context.Context, args []string, force bool) error {
errs = removeContext(s, contextName, errs)
}
}
if errs != nil {
errs.ErrorFormat = formatErrors
}
return errs.ErrorOrNil()
}

func formatErrors(errs []error) string {
messages := make([]string, len(errs))
for i, err := range errs {
messages[i] = "Error: "+err.Error()
}
return strings.Join(messages, "\n")
}

func removeContext(s store.Store, n string, errs *multierror.Error) *multierror.Error {
if err := s.Remove(n); err != nil {
errs = multierror.Append(errs, err)
Expand Down
15 changes: 13 additions & 2 deletions cli/cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package cmd
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/docker/api/client"
"github.com/docker/api/containers"
"github.com/docker/api/errdefs"
"github.com/docker/api/multierror"
)

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

fmt.Println(id)
}

if errs != nil {
errs.ErrorFormat = formatErrors
}
return errs.ErrorOrNil()
}

func formatErrors(errs []error) string {
messages := make([]string, len(errs))
for i, err := range errs {
messages[i] = "Error: "+err.Error()
}
return strings.Join(messages, "\n")
}
108 changes: 0 additions & 108 deletions multierror/multierror.go

This file was deleted.

65 changes: 0 additions & 65 deletions multierror/multierror_test.go

This file was deleted.