mirror of https://github.com/docker/cli.git
Merge 6460abcf1a
into abb8e9b78a
This commit is contained in:
commit
0bf08cefcd
|
@ -2,6 +2,7 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
|
@ -36,17 +37,13 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
|
func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
|
||||||
var errs cli.Errors
|
var errs error
|
||||||
for _, name := range opts.plugins {
|
for _, name := range opts.plugins {
|
||||||
if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil {
|
if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil {
|
||||||
errs = append(errs, err)
|
errs = errors.Join(errs, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), name)
|
_, _ = fmt.Fprintln(dockerCli.Out(), name)
|
||||||
}
|
}
|
||||||
// Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
|
return errs
|
||||||
if errs != nil {
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
18
cli/error.go
18
cli/error.go
|
@ -2,26 +2,8 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Errors is a list of errors.
|
|
||||||
// Useful in a loop if you don't want to return the error right away and you want to display after the loop,
|
|
||||||
// all the errors that happened during the loop.
|
|
||||||
type Errors []error
|
|
||||||
|
|
||||||
func (errList Errors) Error() string {
|
|
||||||
if len(errList) < 1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
out := make([]string, len(errList))
|
|
||||||
for i := range errList {
|
|
||||||
out[i] = errList[i].Error()
|
|
||||||
}
|
|
||||||
return strings.Join(out, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusError reports an unsuccessful exit by a command.
|
// StatusError reports an unsuccessful exit by a command.
|
||||||
type StatusError struct {
|
type StatusError struct {
|
||||||
Status string
|
Status string
|
||||||
|
|
Loading…
Reference in New Issue