mirror of https://github.com/docker/cli.git
Add support for docker push --quiet
Signed-off-by: Justyn Temme <justyntemme@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
37f9a88c69
commit
756ab2fb92
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue