inspect.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package image
  2. import (
  3. "golang.org/x/net/context"
  4. "github.com/docker/docker/cli"
  5. "github.com/docker/docker/cli/command"
  6. "github.com/docker/docker/cli/command/inspect"
  7. "github.com/spf13/cobra"
  8. )
  9. type inspectOptions struct {
  10. format string
  11. refs []string
  12. }
  13. // newInspectCommand creates a new cobra.Command for `docker image inspect`
  14. func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
  15. var opts inspectOptions
  16. cmd := &cobra.Command{
  17. Use: "inspect [OPTIONS] IMAGE [IMAGE...]",
  18. Short: "Display detailed information on one or more images",
  19. Args: cli.RequiresMinArgs(1),
  20. RunE: func(cmd *cobra.Command, args []string) error {
  21. opts.refs = args
  22. return runInspect(dockerCli, opts)
  23. },
  24. }
  25. flags := cmd.Flags()
  26. flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
  27. return cmd
  28. }
  29. func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
  30. client := dockerCli.Client()
  31. ctx := context.Background()
  32. getRefFunc := func(ref string) (interface{}, []byte, error) {
  33. return client.ImageInspectWithRaw(ctx, ref)
  34. }
  35. return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc)
  36. }