mirror of https://github.com/docker/cli.git
Merge pull request #160 from e11137/master
fixes #46 Always exit 0 when remove image with force option
This commit is contained in:
commit
ecc8e0a204
|
@ -56,9 +56,12 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
|||
}
|
||||
|
||||
var errs []string
|
||||
for _, image := range images {
|
||||
dels, err := client.ImageRemove(ctx, image, options)
|
||||
for _, img := range images {
|
||||
dels, err := client.ImageRemove(ctx, img, options)
|
||||
if err != nil {
|
||||
if opts.force {
|
||||
fmt.Fprintf(dockerCli.Out(), "NotFound: %s\n", img)
|
||||
}
|
||||
errs = append(errs, err.Error())
|
||||
} else {
|
||||
for _, del := range dels {
|
||||
|
@ -71,7 +74,7 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
|||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
if !opts.force && len(errs) > 0 {
|
||||
return errors.Errorf("%s", strings.Join(errs, "\n"))
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -67,6 +67,14 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
|||
return []types.ImageDeleteResponseItem{{Deleted: image}}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Image Deleted with force option",
|
||||
args: []string{"-f", "image1"},
|
||||
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
||||
assert.Equal(t, "image1", image)
|
||||
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Image Untagged",
|
||||
args: []string{"image1"},
|
||||
|
|
2
cli/command/image/testdata/remove-command-success.Image Deleted with force option.golden
vendored
Normal file
2
cli/command/image/testdata/remove-command-success.Image Deleted with force option.golden
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
NotFound:image1
|
||||
NotFound:image1
|
Loading…
Reference in New Issue