Fix: docker push --quiet suppressing errors and exit code

Before this patch:

    docker push --quiet nosuchimage
    docker.io/library/nosuchimage

    echo $?
    0

With this patch applied:

    docker push --quiet nosuchimage:latest
    An image does not exist locally with the tag: nosuchimage

    echo $?
    1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2020-01-24 13:53:24 +01:00
parent 74fb129a73
commit 94443920b1
2 changed files with 17 additions and 4 deletions

View File

@ -3,9 +3,11 @@ package image
import (
"context"
"fmt"
"io/ioutil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/streams"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry"
@ -68,9 +70,12 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
}
defer responseBody.Close()
if !opts.quiet {
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
if opts.quiet {
err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(ioutil.Discard), nil)
if err == nil {
fmt.Fprintln(dockerCli.Out(), ref.String())
}
return err
}
fmt.Fprintln(dockerCli.Out(), ref.String())
return nil
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
}