mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
8567286ed6
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
34 lines
871 B
Go
34 lines
871 B
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
Cli "github.com/docker/docker/cli"
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
)
|
|
|
|
// CmdRename renames a container.
|
|
//
|
|
// Usage: docker rename OLD_NAME NEW_NAME
|
|
func (cli *DockerCli) CmdRename(args ...string) error {
|
|
cmd := Cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, Cli.DockerCommands["rename"].Description, true)
|
|
cmd.Require(flag.Exact, 2)
|
|
|
|
cmd.ParseFlags(args, true)
|
|
|
|
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")
|
|
}
|
|
|
|
if err := cli.client.ContainerRename(context.Background(), oldName, newName); err != nil {
|
|
fmt.Fprintf(cli.err, "%s\n", err)
|
|
return fmt.Errorf("Error: failed to rename container named %s", oldName)
|
|
}
|
|
return nil
|
|
}
|