Merge pull request #2197 from thaJeztah/carry_1221_push_quiet

Add support for docker push --quiet
This commit is contained in:
Brian Goff 2019-11-12 16:22:36 -08:00 committed by GitHub
commit 6c12a82f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 14 deletions

View File

@ -2,6 +2,7 @@ package image
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
@ -14,6 +15,7 @@ import (
type pushOptions struct {
remote string
untrusted bool
quiet bool
}
// NewPushCommand creates a new `docker push` command
@ -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
@ -66,5 +68,9 @@ func RunPush(dockerCli command.Cli, opts pushOptions) error {
}
defer responseBody.Close()
if !opts.quiet {
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
}
fmt.Fprintln(dockerCli.Out(), ref.String())
return nil
}

View File

@ -51,21 +51,34 @@ func TestNewPushCommandSuccess(t *testing.T) {
testCases := []struct {
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 {
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(ioutil.Discard)
cmd.SetOutput(cli.OutBuffer())
cmd.SetArgs(tc.args)
assert.NilError(t, cmd.Execute())
if tc.output != "" {
assert.Equal(t, tc.output, cli.OutBuffer().String())
}
})
}
}

View File

@ -3131,7 +3131,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)

View File

@ -23,6 +23,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