github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/container/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 container 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/completion" 12 "github.com/docker/cli/cli/command/inspect" 13 flagsHelper "github.com/docker/cli/cli/flags" 14 "github.com/spf13/cobra" 15 ) 16 17 type inspectOptions struct { 18 format string 19 size bool 20 refs []string 21 } 22 23 // newInspectCommand creates a new cobra.Command for `docker container inspect` 24 func newInspectCommand(dockerCli command.Cli) *cobra.Command { 25 var opts inspectOptions 26 27 cmd := &cobra.Command{ 28 Use: "inspect [OPTIONS] CONTAINER [CONTAINER...]", 29 Short: "Display detailed information on one or more containers", 30 Args: cli.RequiresMinArgs(1), 31 RunE: func(cmd *cobra.Command, args []string) error { 32 opts.refs = args 33 return runInspect(cmd.Context(), dockerCli, opts) 34 }, 35 ValidArgsFunction: completion.ContainerNames(dockerCli, true), 36 } 37 38 flags := cmd.Flags() 39 flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp) 40 flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes") 41 42 return cmd 43 } 44 45 func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error { 46 client := dockerCli.Client() 47 48 getRefFunc := func(ref string) (any, []byte, error) { 49 return client.ContainerInspectWithRaw(ctx, ref, opts.size) 50 } 51 return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc) 52 }