/
rename.go
56 lines (49 loc) · 1.67 KB
/
rename.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package containers
import (
"errors"
"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/pkg/domain/entities"
"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.AutocompleteContainerOneArg,
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() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: renameCommand,
})
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: containerRenameCommand,
Parent: containerCmd,
})
}
func rename(cmd *cobra.Command, args []string) error {
if len(args) > 2 {
return errors.New("must provide at least two arguments to rename")
}
args = utils.RemoveSlash(args)
renameOpts := entities.ContainerRenameOptions{
NewName: args[1],
}
return registry.ContainerEngine().ContainerRename(registry.GetContext(), args[0], renameOpts)
}