summaryrefslogtreecommitdiff
path: root/cmd/podman/inspect.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/inspect.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/inspect.go')
-rw-r--r--cmd/podman/inspect.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go
index 869d16911..dc5810492 100644
--- a/cmd/podman/inspect.go
+++ b/cmd/podman/inspect.go
@@ -33,6 +33,7 @@ var (
Name: "size",
Usage: "Display total file size if the type is container",
},
+ LatestFlag,
}
inspectDescription = "This displays the low-level information on containers and images identified by name or ID. By default, this will render all results in a JSON array. If the container and image have the same name, this will return container JSON for unspecified type."
inspectCommand = cli.Command{
@@ -47,7 +48,10 @@ var (
func inspectCmd(c *cli.Context) error {
args := c.Args()
- if len(args) == 0 {
+ inspectType := c.String("type")
+ latestContainer := c.Bool("latest")
+ var name string
+ if len(args) == 0 && !latestContainer {
return errors.Errorf("container or image name must be specified: podman inspect [options [...]] name")
}
if len(args) > 1 {
@@ -63,17 +67,26 @@ func inspectCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)
- if c.String("type") != inspectTypeContainer && c.String("type") != inspectTypeImage && c.String("type") != inspectAll {
+ if !libpod.StringInSlice(inspectType, []string{inspectTypeContainer, inspectTypeImage, inspectAll}) {
return errors.Errorf("the only recognized types are %q, %q, and %q", inspectTypeContainer, inspectTypeImage, inspectAll)
}
-
- name := args[0]
-
+ if !latestContainer {
+ name = args[0]
+ }
+ if latestContainer {
+ inspectType = inspectTypeContainer
+ }
outputFormat := c.String("format")
var data interface{}
- switch c.String("type") {
+ switch inspectType {
case inspectTypeContainer:
- ctr, err := runtime.LookupContainer(name)
+ var ctr *libpod.Container
+ var err error
+ if latestContainer {
+ ctr, err = runtime.GetLatestContainer()
+ } else {
+ ctr, err = runtime.LookupContainer(name)
+ }
if err != nil {
return errors.Wrapf(err, "error looking up container %q", name)
}