mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Fix podman inspect to accept -l and -s fields
Podman inspect has a breaking change in that it dropped --latest and --size options. This PR adds these back. Lots of tests rely on podman inspect -l. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -20,11 +20,13 @@ import (
|
|||||||
var (
|
var (
|
||||||
// Command: podman image _inspect_
|
// Command: podman image _inspect_
|
||||||
inspectCmd = &cobra.Command{
|
inspectCmd = &cobra.Command{
|
||||||
Use: "inspect [flags] IMAGE",
|
Use: "inspect [flags] IMAGE",
|
||||||
Short: "Display the configuration of an image",
|
Short: "Display the configuration of an image",
|
||||||
Long: `Displays the low-level information on an image identified by name or ID.`,
|
Long: `Displays the low-level information on an image identified by name or ID.`,
|
||||||
RunE: inspect,
|
RunE: inspect,
|
||||||
Example: `podman image inspect alpine`,
|
Example: `podman inspect alpine
|
||||||
|
podman inspect --format "imageId: {{.Id}} size: {{.Size}}" alpine
|
||||||
|
podman inspect --format "image: {{.ImageName}} driver: {{.Driver}}" myctr`,
|
||||||
}
|
}
|
||||||
inspectOpts *entities.InspectOptions
|
inspectOpts *entities.InspectOptions
|
||||||
)
|
)
|
||||||
@ -39,14 +41,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inspect(cmd *cobra.Command, args []string) error {
|
func inspect(cmd *cobra.Command, args []string) error {
|
||||||
latestContainer := inspectOpts.Latest
|
if inspectOpts.Size {
|
||||||
|
return fmt.Errorf("--size can only be used for containers")
|
||||||
if len(args) == 0 && !latestContainer {
|
|
||||||
return errors.Errorf("container or image name must be specified: podman inspect [options [...]] name")
|
|
||||||
}
|
}
|
||||||
|
if inspectOpts.Latest {
|
||||||
if len(args) > 0 && latestContainer {
|
return fmt.Errorf("--latest can only be used for containers")
|
||||||
return errors.Errorf("you cannot provide additional arguments with --latest")
|
}
|
||||||
|
if len(args) == 0 {
|
||||||
|
return errors.Errorf("image name must be specified: podman image inspect [options [...]] name")
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err := registry.ImageEngine().Inspect(context.Background(), args, *inspectOpts)
|
results, err := registry.ImageEngine().Inspect(context.Background(), args, *inspectOpts)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/containers/image/v5/docker/reference"
|
|
||||||
"github.com/containers/libpod/cmd/podman/common"
|
"github.com/containers/libpod/cmd/podman/common"
|
||||||
"github.com/containers/libpod/cmd/podman/containers"
|
"github.com/containers/libpod/cmd/podman/containers"
|
||||||
"github.com/containers/libpod/cmd/podman/images"
|
"github.com/containers/libpod/cmd/podman/images"
|
||||||
@ -21,11 +19,12 @@ var (
|
|||||||
// Command: podman _inspect_ Object_ID
|
// Command: podman _inspect_ Object_ID
|
||||||
inspectCmd = &cobra.Command{
|
inspectCmd = &cobra.Command{
|
||||||
Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID}",
|
Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID}",
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
Short: "Display the configuration of object denoted by ID",
|
Short: "Display the configuration of object denoted by ID",
|
||||||
Long: "Displays the low-level information on an object identified by name or ID",
|
Long: "Displays the low-level information on an object identified by name or ID",
|
||||||
TraverseChildren: true,
|
TraverseChildren: true,
|
||||||
RunE: inspect,
|
RunE: inspect,
|
||||||
|
Example: `podman inspect alpine
|
||||||
|
podman inspect --format "imageId: {{.Id}} size: {{.Size}}" alpine`,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,21 +34,25 @@ func init() {
|
|||||||
Command: inspectCmd,
|
Command: inspectCmd,
|
||||||
})
|
})
|
||||||
inspectOpts = common.AddInspectFlagSet(inspectCmd)
|
inspectOpts = common.AddInspectFlagSet(inspectCmd)
|
||||||
|
flags := inspectCmd.Flags()
|
||||||
|
flags.StringVarP(&inspectOpts.Type, "type", "t", "", "Return JSON for specified type, (image or container) (default \"all\")")
|
||||||
|
if !registry.IsRemote() {
|
||||||
|
flags.BoolVarP(&inspectOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of (containers only)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspect(cmd *cobra.Command, args []string) error {
|
func inspect(cmd *cobra.Command, args []string) error {
|
||||||
// First check if the input is even valid for an image
|
switch inspectOpts.Type {
|
||||||
if _, err := reference.Parse(args[0]); err == nil {
|
case "image":
|
||||||
if found, err := registry.ImageEngine().Exists(context.Background(), args[0]); err != nil {
|
return images.Inspect(cmd, args, inspectOpts)
|
||||||
return err
|
case "container":
|
||||||
} else if found.Value {
|
|
||||||
return images.Inspect(cmd, args, inspectOpts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if found, err := registry.ContainerEngine().ContainerExists(context.Background(), args[0]); err != nil {
|
|
||||||
return err
|
|
||||||
} else if found.Value {
|
|
||||||
return containers.Inspect(cmd, args, inspectOpts)
|
return containers.Inspect(cmd, args, inspectOpts)
|
||||||
|
case "":
|
||||||
|
if err := images.Inspect(cmd, args, inspectOpts); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return containers.Inspect(cmd, args, inspectOpts)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid type %q is must be 'container' or 'image'", inspectOpts.Type)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s not found on system", args[0])
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ type InspectOptions struct {
|
|||||||
Format string `json:",omitempty"`
|
Format string `json:",omitempty"`
|
||||||
Latest bool `json:",omitempty"`
|
Latest bool `json:",omitempty"`
|
||||||
Size bool `json:",omitempty"`
|
Size bool `json:",omitempty"`
|
||||||
|
Type string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// All API and CLI diff commands and diff sub-commands use the same options
|
// All API and CLI diff commands and diff sub-commands use the same options
|
||||||
|
Reference in New Issue
Block a user