Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[19.03 backport] Add support for docker push --quiet #2567

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli/command/image/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package image

import (
"context"
"fmt"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand All @@ -14,6 +15,7 @@ import (
type pushOptions struct {
remote string
untrusted bool
quiet bool
}

// NewPushCommand creates a new `docker push` command
Expand All @@ -31,7 +33,7 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command {
}

flags := cmd.Flags()

flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())

return cmd
Expand Down Expand Up @@ -66,5 +68,9 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
}

defer responseBody.Close()
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
if !opts.quiet {
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
}
fmt.Fprintln(dockerCli.Out(), ref.String())
return nil
}
35 changes: 24 additions & 11 deletions cli/command/image/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,36 @@ func TestNewPushCommandErrors(t *testing.T) {

func TestNewPushCommandSuccess(t *testing.T) {
testCases := []struct {
name string
args []string
name string
args []string
output string
}{
{
name: "simple",
name: "push",
args: []string{"image:tag"},
},
{
name: "push quiet",
args: []string{"--quiet", "image:tag"},
output: `docker.io/library/image:tag
`,
},
}
for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("")), nil
},
tc := tc
t.Run(tc.name, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
imagePushFunc: func(ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("")), nil
},
})
cmd := NewPushCommand(cli)
cmd.SetOutput(cli.OutBuffer())
cmd.SetArgs(tc.args)
assert.NilError(t, cmd.Execute())
if tc.output != "" {
assert.Equal(t, tc.output, cli.OutBuffer().String())
}
})
cmd := NewPushCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.NilError(t, cmd.Execute())
}
}
2 changes: 1 addition & 1 deletion contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ _docker_image_pull() {
_docker_image_push() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--disable-content-trust=false --help --quiet -q" -- "$cur" ) )
;;
*)
local counter=$(__docker_pos_first_nonflag)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/commandline/push.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Push an image or a repository to a registry
Options:
--disable-content-trust Skip image signing (default true)
--help Print usage
-q, --quiet Suppress verbose output
```

## Description
Expand Down