Merge pull request #160 from e11137/master

fixes #46 Always exit 0 when remove image with force option
This commit is contained in:
Vincent Demeester 2017-06-13 14:02:02 +02:00 committed by GitHub
commit ecc8e0a204
3 changed files with 16 additions and 3 deletions

View File

@ -56,9 +56,12 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
} }
var errs []string var errs []string
for _, image := range images { for _, img := range images {
dels, err := client.ImageRemove(ctx, image, options) dels, err := client.ImageRemove(ctx, img, options)
if err != nil { if err != nil {
if opts.force {
fmt.Fprintf(dockerCli.Out(), "NotFound: %s\n", img)
}
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {
for _, del := range dels { 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 errors.Errorf("%s", strings.Join(errs, "\n"))
} }
return nil return nil

View File

@ -67,6 +67,14 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
return []types.ImageDeleteResponseItem{{Deleted: image}}, nil 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", name: "Image Untagged",
args: []string{"image1"}, args: []string{"image1"},

View File

@ -0,0 +1,2 @@
NotFound:image1
NotFound:image1