github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/cli/command/container/inspect.go (about)

     1  package container
     2  
     3  import (
     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  	"golang.org/x/net/context"
     9  )
    10  
    11  type inspectOptions struct {
    12  	format string
    13  	size   bool
    14  	refs   []string
    15  }
    16  
    17  // newInspectCommand creates a new cobra.Command for `docker container inspect`
    18  func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
    19  	var opts inspectOptions
    20  
    21  	cmd := &cobra.Command{
    22  		Use:   "inspect [OPTIONS] CONTAINER [CONTAINER...]",
    23  		Short: "Display detailed information on one or more containers",
    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  	flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes")
    34  
    35  	return cmd
    36  }
    37  
    38  func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
    39  	client := dockerCli.Client()
    40  	ctx := context.Background()
    41  
    42  	getRefFunc := func(ref string) (interface{}, []byte, error) {
    43  		return client.ContainerInspectWithRaw(ctx, ref, opts.size)
    44  	}
    45  	return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc)
    46  }