2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
2015-04-29 07:37:20 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2015-09-18 14:05:04 -04:00
|
|
|
"strings"
|
2015-04-29 07:37:20 -04:00
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-04-29 07:37:20 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
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 {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, Cli.DockerCommands["rename"].Description, true)
|
2015-04-29 07:37:20 -04:00
|
|
|
cmd.Require(flag.Exact, 2)
|
2015-07-03 05:26:09 -04:00
|
|
|
|
2015-04-29 07:37:20 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-09-18 14:05:04 -04:00
|
|
|
oldName := strings.TrimSpace(cmd.Arg(0))
|
|
|
|
newName := strings.TrimSpace(cmd.Arg(1))
|
|
|
|
|
|
|
|
if oldName == "" || newName == "" {
|
|
|
|
return fmt.Errorf("Error: Neither old nor new names may be empty")
|
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
if err := cli.client.ContainerRename(context.Background(), oldName, newName); 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
|
|
|
|
}
|