Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// renameDescription is used to describe rename command in detail and auto generate command doc. | ||
var renameDescription = "Rename a container object in Pouchd. " + | ||
"You can change the name of one container identified by it's name or ID. " + | ||
"The container you renamed is ready to be used by it's new name." | ||
|
||
// RenameCommand uses to implement 'rename' command, it renames a container. | ||
type RenameCommand struct { | ||
baseCommand | ||
} | ||
|
||
// Init initialize rename command. | ||
func (rc *RenameCommand) Init(c *Cli) { | ||
rc.cli = c | ||
|
||
rc.cmd = &cobra.Command{ | ||
Use: "rename [container] [newName]", | ||
Short: "Rename a container with newName", | ||
Long: renameDescription, | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return rc.runRename(args) | ||
}, | ||
Example: renameExample(), | ||
} | ||
} | ||
|
||
// runRename is the entry of rename command. | ||
func (rc *RenameCommand) runRename(args []string) error { | ||
apiClient := rc.cli.Client() | ||
container := args[0] | ||
newName := args[1] | ||
|
||
err := apiClient.ContainerRename(container, newName) | ||
|
||
return err | ||
} | ||
|
||
// renameExample shows examples in rename command, and is used in auto-generated cli docs. | ||
func renameExample() string { | ||
return `$ pouch ps | ||
Name ID Status Image | ||
foo 71b9c1 Running docker.io/library/busybox:latest | ||
$ pouch rename foo newName | ||
$ pouch ps | ||
Name ID Status Image | ||
newName 71b9c1 Running docker.io/library/busybox:latest | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters