summaryrefslogtreecommitdiff
path: root/cmd/podman/logs.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/logs.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/logs.go')
-rw-r--r--cmd/podman/logs.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go
index 8745d5d7f..b31dce2d3 100644
--- a/cmd/podman/logs.go
+++ b/cmd/podman/logs.go
@@ -37,6 +37,7 @@ var (
Name: "tail",
Usage: "Output the specified number of LINES at the end of the logs. Defaults to 0, which prints all lines",
},
+ LatestFlag,
}
logsDescription = "The podman logs command batch-retrieves whatever logs are present for a container at the time of execution. This does not guarantee execution" +
"order when combined with podman run (i.e. your run may not have generated any logs at the time you execute podman logs"
@@ -51,6 +52,8 @@ var (
)
func logsCmd(c *cli.Context) error {
+ var ctr *libpod.Container
+ var err error
if err := validateFlags(c, logsFlags); err != nil {
return err
}
@@ -62,7 +65,7 @@ func logsCmd(c *cli.Context) error {
defer runtime.Shutdown(false)
args := c.Args()
- if len(args) != 1 {
+ if len(args) != 1 && !c.Bool("latest") {
return errors.Errorf("'podman logs' requires exactly one container name/ID")
}
@@ -83,7 +86,11 @@ func logsCmd(c *cli.Context) error {
tail: c.Uint64("tail"),
}
- 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 err
}