github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/image/tag.go (about) 1 package image 2 3 import ( 4 "golang.org/x/net/context" 5 6 "github.com/docker/docker/cli" 7 "github.com/docker/docker/cli/command" 8 "github.com/spf13/cobra" 9 ) 10 11 type tagOptions struct { 12 image string 13 name string 14 } 15 16 // NewTagCommand creates a new `docker tag` command 17 func NewTagCommand(dockerCli *command.DockerCli) *cobra.Command { 18 var opts tagOptions 19 20 cmd := &cobra.Command{ 21 Use: "tag IMAGE[:TAG] IMAGE[:TAG]", 22 Short: "Tag an image into a repository", 23 Args: cli.ExactArgs(2), 24 RunE: func(cmd *cobra.Command, args []string) error { 25 opts.image = args[0] 26 opts.name = args[1] 27 return runTag(dockerCli, opts) 28 }, 29 } 30 31 flags := cmd.Flags() 32 flags.SetInterspersed(false) 33 34 return cmd 35 } 36 37 func runTag(dockerCli *command.DockerCli, opts tagOptions) error { 38 ctx := context.Background() 39 40 return dockerCli.Client().ImageTag(ctx, opts.image, opts.name) 41 }