diff options
author | Brent Baude <bbaude@redhat.com> | 2020-03-26 13:37:09 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-03-26 15:54:26 -0500 |
commit | 2fa78938a94e90e41755b68dd1af36f5b817ed55 (patch) | |
tree | f6a1161387751d8a413c0ebe66ba253f4a91a1af /cmd | |
parent | 6a46a87d08bd1e9ddda3dd3c9c30d21d2226a654 (diff) | |
download | podman-2fa78938a94e90e41755b68dd1af36f5b817ed55.tar.gz podman-2fa78938a94e90e41755b68dd1af36f5b817ed55.tar.bz2 podman-2fa78938a94e90e41755b68dd1af36f5b817ed55.zip |
podmanv2 container inspect
add ability to inspect a container
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podmanV2/containers/inspect.go | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/cmd/podmanV2/containers/inspect.go b/cmd/podmanV2/containers/inspect.go index 635be4789..648289f0b 100644 --- a/cmd/podmanV2/containers/inspect.go +++ b/cmd/podmanV2/containers/inspect.go @@ -1,8 +1,15 @@ package containers import ( + "context" + "fmt" + "os" + "strings" + "text/template" + "github.com/containers/libpod/cmd/podmanV2/registry" "github.com/containers/libpod/pkg/domain/entities" + jsoniter "github.com/json-iterator/go" "github.com/spf13/cobra" ) @@ -12,31 +19,57 @@ var ( Use: "inspect [flags] CONTAINER", Short: "Display the configuration of a container", Long: `Displays the low-level information on a container identified by name or ID.`, - PreRunE: inspectPreRunE, + PreRunE: preRunE, RunE: inspect, Example: `podman container inspect myCtr podman container inspect -l --format '{{.Id}} {{.Config.Labels}}'`, } ) +var ( + inspectOptions entities.ContainerInspectOptions +) + func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: inspectCmd, Parent: containerCmd, }) -} - -func inspectPreRunE(cmd *cobra.Command, args []string) (err error) { - err = preRunE(cmd, args) - if err != nil { - return + flags := inspectCmd.Flags() + flags.StringVarP(&inspectOptions.Format, "format", "f", "", "Change the output format to a Go template") + flags.BoolVarP(&inspectOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of") + flags.BoolVarP(&inspectOptions.Size, "size", "s", false, "Display total file size") + if registry.IsRemote() { + _ = flags.MarkHidden("latest") } - - _, err = registry.NewImageEngine(cmd, args) - return err } func inspect(cmd *cobra.Command, args []string) error { + responses, err := registry.ContainerEngine().ContainerInspect(context.Background(), args, inspectOptions) + if err != nil { + return err + } + if inspectOptions.Format == "" { + b, err := jsoniter.MarshalIndent(responses, "", " ") + if err != nil { + return err + } + fmt.Println(string(b)) + return nil + } + format := inspectOptions.Format + if !strings.HasSuffix(format, "\n") { + format += "\n" + } + tmpl, err := template.New("inspect").Parse(format) + if err != nil { + return err + } + for _, i := range responses { + if err := tmpl.Execute(os.Stdout, i); err != nil { + return err + } + } return nil } |