github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/image/inspect.go (about)

     1  package image
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/docker/cli/cli"
     7  	"github.com/docker/cli/cli/command"
     8  	"github.com/docker/cli/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.Cli) *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.Cli, 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  }