diff --git a/api/client/commands.go b/api/client/commands.go index fcd5a311bb..fbc76b00b9 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -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] diff --git a/api/client/image/tag.go b/api/client/image/tag.go new file mode 100644 index 0000000000..5c0b569fb5 --- /dev/null +++ b/api/client/image/tag.go @@ -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) +} diff --git a/api/client/tag.go b/api/client/tag.go deleted file mode 100644 index 0b6a073ccb..0000000000 --- a/api/client/tag.go +++ /dev/null @@ -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)) -} diff --git a/cli/cobraadaptor/adaptor.go b/cli/cobraadaptor/adaptor.go index 0d536f0608..8c73831f4a 100644 --- a/cli/cobraadaptor/adaptor.go +++ b/cli/cobraadaptor/adaptor.go @@ -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), ) diff --git a/cli/usage.go b/cli/usage.go index baf4948931..b8314eb0ab 100644 --- a/cli/usage.go +++ b/cli/usage.go @@ -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"}, }