summaryrefslogtreecommitdiff
path: root/cmd/podman/exec.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/exec.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/exec.go')
-rw-r--r--cmd/podman/exec.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go
index 7a0bab617..07ef3a0cd 100644
--- a/cmd/podman/exec.go
+++ b/cmd/podman/exec.go
@@ -27,6 +27,7 @@ var (
Name: "user, u",
Usage: "Sets the username or UID used and optionally the groupname or GID for the specified command",
},
+ LatestFlag,
}
execDescription = `
podman exec
@@ -48,20 +49,30 @@ var (
func execCmd(c *cli.Context) error {
var envs []string
args := c.Args()
- if len(args) < 1 {
+ var ctr *libpod.Container
+ var err error
+ argStart := 1
+ if len(args) < 1 && !c.Bool("latest") {
return errors.Errorf("you must provide one container name or id")
}
- if len(args) < 2 {
+ if len(args) < 2 && !c.Bool("latest") {
return errors.Errorf("you must provide a command to exec")
}
- cmd := args[1:]
+ if c.Bool("latest") {
+ argStart = 0
+ }
+ cmd := args[argStart:]
runtime, err := getRuntime(c)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- ctr, err := runtime.LookupContainer(args[0])
+ if c.Bool("latest") {
+ ctr, err = runtime.GetLatestContainer()
+ } else {
+ ctr, err = runtime.LookupContainer(args[0])
+ }
if err != nil {
return errors.Wrapf(err, "unable to exec into %s", args[0])
}