summaryrefslogtreecommitdiff
path: root/cmd/podman/stop.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-01-02 16:29:43 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-08 19:12:17 +0000
commit7b08aa78e4ede4c54fda6cd9917bb62e18d0d634 (patch)
tree1c480d9dfb8db3268dc3fdcca827792278a3ae47 /cmd/podman/stop.go
parent6baf6e461de6e560cc48d35239e7c392bec4481c (diff)
downloadpodman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.gz
podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.bz2
podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.zip
Shortcut for most recent container
It is desirable to have a shortcut for the most recently created container. We can now use "**latest" to represent the most recent container instead of its container ID or name. For example: Signed-off-by: baude <bbaude@redhat.com> Closes: #179 Approved by: baude
Diffstat (limited to 'cmd/podman/stop.go')
-rw-r--r--cmd/podman/stop.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go
index f85512d47..d18a05bd4 100644
--- a/cmd/podman/stop.go
+++ b/cmd/podman/stop.go
@@ -19,7 +19,7 @@ var (
cli.BoolFlag{
Name: "all, a",
Usage: "stop all running containers",
- },
+ }, LatestFlag,
}
stopDescription = `
podman stop
@@ -41,10 +41,13 @@ var (
func stopCmd(c *cli.Context) error {
args := c.Args()
- if c.Bool("all") && len(args) > 0 {
- return errors.Errorf("no arguments are needed with -a")
+ if (c.Bool("all") || c.Bool("latest")) && len(args) > 0 {
+ return errors.Errorf("no arguments are needed with --all or --latest")
+ }
+ if c.Bool("all") && c.Bool("latest") {
+ return errors.Errorf("--all and --latest cannot be used together")
}
- if len(args) < 1 && !c.Bool("all") {
+ if len(args) < 1 && !c.Bool("all") && !c.Bool("latest") {
return errors.Errorf("you must provide at least one container name or id")
}
if err := validateFlags(c, stopFlags); err != nil {
@@ -71,6 +74,12 @@ func stopCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "unable to get running containers")
}
+ } else if c.Bool("latest") {
+ lastCtr, err := runtime.GetLatestContainer()
+ if err != nil {
+ return errors.Wrapf(err, "unable to get last created container")
+ }
+ containers = append(containers, lastCtr)
} else {
for _, i := range args {
container, err := runtime.LookupContainer(i)