Use spf13/cobra for docker tag

This fix is part of the effort to convert commands to spf13/cobra #23211.

Thif fix coverted command `docker tag` to use spf13/cobra

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2016-06-05 11:05:35 -07:00
Родитель a01ae049f9
Коммит ba7324ffcb
5 изменённых файлов: 42 добавлений и 22 удалений

Просмотреть файл

@ -20,7 +20,6 @@ func (cli *DockerCli) Command(name string) func(...string) error {
"rm": cli.CmdRm,
"save": cli.CmdSave,
"stats": cli.CmdStats,
"tag": cli.CmdTag,
"update": cli.CmdUpdate,
"version": cli.CmdVersion,
}[name]

41
api/client/image/tag.go Normal file
Просмотреть файл

@ -0,0 +1,41 @@
package image
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/client"
"github.com/docker/docker/cli"
"github.com/spf13/cobra"
)
type tagOptions struct {
image string
name string
}
// NewTagCommand create a new `docker tag` command
func NewTagCommand(dockerCli *client.DockerCli) *cobra.Command {
var opts tagOptions
cmd := &cobra.Command{
Use: "tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]",
Short: "Tag an image into a repository",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
opts.image = args[0]
opts.name = args[1]
return runTag(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.SetInterspersed(false)
return cmd
}
func runTag(dockerCli *client.DockerCli, opts tagOptions) error {
ctx := context.Background()
return dockerCli.Client().ImageTag(ctx, opts.image, opts.name)
}

Просмотреть файл

@ -1,20 +0,0 @@
package client
import (
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
)
// CmdTag tags an image into a repository.
//
// Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
func (cli *DockerCli) CmdTag(args ...string) error {
cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true)
cmd.Require(flag.Exact, 2)
cmd.ParseFlags(args, true)
return cli.client.ImageTag(context.Background(), cmd.Arg(0), cmd.Arg(1))
}

Просмотреть файл

@ -54,6 +54,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
image.NewRemoveCommand(dockerCli),
image.NewSearchCommand(dockerCli),
image.NewImportCommand(dockerCli),
image.NewTagCommand(dockerCli),
network.NewNetworkCommand(dockerCli),
volume.NewVolumeCommand(dockerCli),
)

Просмотреть файл

@ -25,7 +25,6 @@ var DockerCommandUsage = []Command{
{"rm", "Remove one or more containers"},
{"save", "Save one or more images to a tar archive"},
{"stats", "Display a live stream of container(s) resource usage statistics"},
{"tag", "Tag an image into a repository"},
{"update", "Update configuration of one or more containers"},
{"version", "Show the Docker version information"},
}