2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdRename renames a container.
|
|
|
|
//
|
|
|
|
// Usage: docker rename OLD_NAME NEW_NAME
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdRename(args ...string) error {
|
|
|
|
cmd := cli.Subcmd("rename", "OLD_NAME NEW_NAME", "Rename a container", true)
|
|
|
|
if err := cmd.Parse(args); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.NArg() != 2 {
|
|
|
|
cmd.Usage()
|
|
|
|
return nil
|
|
|
|
}
|
2015-03-25 22:31:29 -04:00
|
|
|
oldName := cmd.Arg(0)
|
|
|
|
newName := cmd.Arg(1)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-01-12 14:56:01 -05:00
|
|
|
if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
fmt.Fprintf(cli.err, "%s\n", err)
|
2015-03-25 22:31:29 -04:00
|
|
|
return fmt.Errorf("Error: failed to rename container named %s", oldName)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|