github.com/a4a881d4/docker@v1.9.0-rc2/api/client/tag.go (about) 1 package client 2 3 import ( 4 "net/url" 5 6 Cli "github.com/docker/docker/cli" 7 flag "github.com/docker/docker/pkg/mflag" 8 "github.com/docker/docker/pkg/parsers" 9 "github.com/docker/docker/registry" 10 ) 11 12 // CmdTag tags an image into a repository. 13 // 14 // Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] 15 func (cli *DockerCli) CmdTag(args ...string) error { 16 cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true) 17 force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force") 18 cmd.Require(flag.Exact, 2) 19 20 cmd.ParseFlags(args, true) 21 22 var ( 23 repository, tag = parsers.ParseRepositoryTag(cmd.Arg(1)) 24 v = url.Values{} 25 ) 26 27 //Check if the given image name can be resolved 28 if err := registry.ValidateRepositoryName(repository); err != nil { 29 return err 30 } 31 v.Set("repo", repository) 32 v.Set("tag", tag) 33 34 if *force { 35 v.Set("force", "1") 36 } 37 38 if _, _, err := readBody(cli.call("POST", "/images/"+cmd.Arg(0)+"/tag?"+v.Encode(), nil, nil)); err != nil { 39 return err 40 } 41 return nil 42 }