github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/api/client/tag.go (about)

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