summaryrefslogtreecommitdiff
path: root/cmd/podman/attach.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/attach.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/attach.go')
-rw-r--r--cmd/podman/attach.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index 8c2c99fd5..e468964f6 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -19,6 +19,7 @@ var (
Name: "no-stdin",
Usage: "Do not attach STDIN. The default is false.",
},
+ LatestFlag,
}
attachDescription = "The podman attach command allows you to attach to a running container using the container's ID or name, either to view its ongoing output or to control it interactively."
attachCommand = cli.Command{
@@ -33,12 +34,12 @@ var (
func attachCmd(c *cli.Context) error {
args := c.Args()
+ var ctr *libpod.Container
if err := validateFlags(c, attachFlags); err != nil {
return err
}
-
- if len(c.Args()) < 1 || len(c.Args()) > 1 {
- return errors.Errorf("attach requires the name or id of one running container")
+ if len(c.Args()) > 1 || (len(c.Args()) == 0 && !c.Bool("latest")) {
+ return errors.Errorf("attach requires the name or id of one running container or the latest flag")
}
runtime, err := getRuntime(c)
@@ -47,7 +48,11 @@ func attachCmd(c *cli.Context) error {
}
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])