summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/rename.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/cmd/podman/containers/rename.go b/cmd/podman/containers/rename.go
new file mode 100644
index 000000000..9c94e6272
--- /dev/null
+++ b/cmd/podman/containers/rename.go
@@ -0,0 +1,56 @@
+package containers
+
+import (
+ "github.com/containers/podman/v2/cmd/podman/common"
+ "github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ renameDescription = "The podman rename command allows you to rename an existing container"
+ renameCommand = &cobra.Command{
+ Use: "rename CONTAINER NAME",
+ Short: "Rename an existing container",
+ Long: renameDescription,
+ RunE: rename,
+ Args: cobra.ExactArgs(2),
+ ValidArgsFunction: common.AutocompletePortCommand,
+ Example: "podman rename containerA newName",
+ }
+
+ containerRenameCommand = &cobra.Command{
+ Use: renameCommand.Use,
+ Short: renameCommand.Short,
+ Long: renameCommand.Long,
+ RunE: renameCommand.RunE,
+ Args: renameCommand.Args,
+ ValidArgsFunction: renameCommand.ValidArgsFunction,
+ Example: "podman container rename containerA newName",
+ }
+)
+
+func init() {
+ // TODO: Once bindings are done, add this to TunnelMode
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode},
+ Command: renameCommand,
+ })
+
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode},
+ Command: containerRenameCommand,
+ Parent: containerCmd,
+ })
+}
+
+func rename(cmd *cobra.Command, args []string) error {
+ if len(args) > 2 {
+ return errors.Errorf("must provide at least two arguments to rename")
+ }
+ renameOpts := entities.ContainerRenameOptions{
+ NewName: args[1],
+ }
+ return registry.ContainerEngine().ContainerRename(registry.GetContext(), args[0], renameOpts)
+}