github.com/goern/docker@v1.9.0-rc1/api/client/rename.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	Cli "github.com/docker/docker/cli"
     8  	flag "github.com/docker/docker/pkg/mflag"
     9  )
    10  
    11  // CmdRename renames a container.
    12  //
    13  // Usage: docker rename OLD_NAME NEW_NAME
    14  func (cli *DockerCli) CmdRename(args ...string) error {
    15  	cmd := Cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, Cli.DockerCommands["rename"].Description, true)
    16  	cmd.Require(flag.Exact, 2)
    17  
    18  	cmd.ParseFlags(args, true)
    19  
    20  	oldName := strings.TrimSpace(cmd.Arg(0))
    21  	newName := strings.TrimSpace(cmd.Arg(1))
    22  
    23  	if oldName == "" || newName == "" {
    24  		return fmt.Errorf("Error: Neither old nor new names may be empty")
    25  	}
    26  
    27  	if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
    28  		fmt.Fprintf(cli.err, "%s\n", err)
    29  		return fmt.Errorf("Error: failed to rename container named %s", oldName)
    30  	}
    31  	return nil
    32  }