2016-06-05 18:05:35 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-08-25 13:29:59 +00:00
|
|
|
// NewTagCommand creates a new `docker tag` command
|
2016-06-05 18:05:35 +00:00
|
|
|
func NewTagCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
|
var opts tagOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2016-07-07 18:43:18 +00:00
|
|
|
Use: "tag IMAGE[:TAG] IMAGE[:TAG]",
|
2016-06-05 18:05:35 +00:00
|
|
|
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)
|
|
|
|
}
|