summaryrefslogtreecommitdiff
path: root/cmd/podmanV2
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-03-26 22:43:38 +0100
committerGitHub <noreply@github.com>2020-03-26 22:43:38 +0100
commit1710eca4e930f7ed3a2b060029c627c1a66a2349 (patch)
treef6a1161387751d8a413c0ebe66ba253f4a91a1af /cmd/podmanV2
parent6a46a87d08bd1e9ddda3dd3c9c30d21d2226a654 (diff)
parent2fa78938a94e90e41755b68dd1af36f5b817ed55 (diff)
downloadpodman-1710eca4e930f7ed3a2b060029c627c1a66a2349.tar.gz
podman-1710eca4e930f7ed3a2b060029c627c1a66a2349.tar.bz2
podman-1710eca4e930f7ed3a2b060029c627c1a66a2349.zip
Merge pull request #5629 from baude/v2containerinspect
podmanv2 container inspect
Diffstat (limited to 'cmd/podmanV2')
-rw-r--r--cmd/podmanV2/containers/inspect.go53
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
}