github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cli/command/image/inspect.go (about) 1 // FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16: 2 //go:build go1.19 3 4 package image 5 6 import ( 7 "context" 8 9 "github.com/docker/cli/cli" 10 "github.com/docker/cli/cli/command" 11 "github.com/docker/cli/cli/command/inspect" 12 flagsHelper "github.com/docker/cli/cli/flags" 13 "github.com/spf13/cobra" 14 ) 15 16 type inspectOptions struct { 17 format string 18 refs []string 19 } 20 21 // newInspectCommand creates a new cobra.Command for `docker image inspect` 22 func newInspectCommand(dockerCli command.Cli) *cobra.Command { 23 var opts inspectOptions 24 25 cmd := &cobra.Command{ 26 Use: "inspect [OPTIONS] IMAGE [IMAGE...]", 27 Short: "Display detailed information on one or more images", 28 Args: cli.RequiresMinArgs(1), 29 RunE: func(cmd *cobra.Command, args []string) error { 30 opts.refs = args 31 return runInspect(cmd.Context(), dockerCli, opts) 32 }, 33 } 34 35 flags := cmd.Flags() 36 flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp) 37 return cmd 38 } 39 40 func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error { 41 client := dockerCli.Client() 42 getRefFunc := func(ref string) (any, []byte, error) { 43 return client.ImageInspectWithRaw(ctx, ref) 44 } 45 return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc) 46 }