mirror of https://github.com/docker/cli.git
cli/command/plugins: use errors.Join instead of custom cli.Errors
This command was using a custom "multi-error" implementation, but it
had some limitations, and the formatting wasn't great.
This patch replaces it with Go's errors.Join.
Before:
docker plugin remove one two three
Error response from daemon: plugin "one" not found, Error response from daemon: plugin "two" not found, Error response from daemon: plugin "three" not found
After:
docker plugin remove one two three
Error response from daemon: plugin "one" not found
Error response from daemon: plugin "two" not found
Error response from daemon: plugin "three" not found
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 71ebbb81ae
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0008d79159
commit
d3bf82db86
|
@ -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.
|
|
||||||
if errs != nil {
|
|
||||||
return errs
|
return errs
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue