github.com/feiyang21687/docker@v1.5.0/graph/tag.go (about)

     1  package graph
     2  
     3  import (
     4  	"github.com/docker/docker/engine"
     5  	"github.com/docker/docker/pkg/parsers"
     6  )
     7  
     8  // CmdTag assigns a new name and tag to an existing image. If the tag already exists,
     9  // it is changed and the image previously referenced by the tag loses that reference.
    10  // This may cause the old image to be garbage-collected if its reference count reaches zero.
    11  //
    12  // Syntax: image_tag NEWNAME OLDNAME
    13  // Example: image_tag shykes/myapp:latest shykes/myapp:1.42.0
    14  func (s *TagStore) CmdTag(job *engine.Job) engine.Status {
    15  	if len(job.Args) != 2 {
    16  		return job.Errorf("usage: %s NEWNAME OLDNAME", job.Name)
    17  	}
    18  	var (
    19  		newName = job.Args[0]
    20  		oldName = job.Args[1]
    21  	)
    22  	newRepo, newTag := parsers.ParseRepositoryTag(newName)
    23  	// FIXME: Set should either parse both old and new name, or neither.
    24  	// 	the current prototype is inconsistent.
    25  	if err := s.Set(newRepo, newTag, oldName, true); err != nil {
    26  		return job.Error(err)
    27  	}
    28  	return engine.StatusOK
    29  }
    30  
    31  // FIXME: merge into CmdTag above, and merge "image_tag" and "tag" into a single job.
    32  func (s *TagStore) CmdTagLegacy(job *engine.Job) engine.Status {
    33  	if len(job.Args) != 2 && len(job.Args) != 3 {
    34  		return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
    35  	}
    36  	var tag string
    37  	if len(job.Args) == 3 {
    38  		tag = job.Args[2]
    39  	}
    40  	if err := s.Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
    41  		return job.Error(err)
    42  	}
    43  	return engine.StatusOK
    44  }