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