newInspectCommand creates a new cobra.Command for `docker inspect`
(dockerCLI command.Cli)
| 57 | |
| 58 | // newInspectCommand creates a new cobra.Command for `docker inspect` |
| 59 | func newInspectCommand(dockerCLI command.Cli) *cobra.Command { |
| 60 | var opts inspectOptions |
| 61 | |
| 62 | cmd := &cobra.Command{ |
| 63 | Use: "inspect [OPTIONS] NAME|ID [NAME|ID...]", |
| 64 | Short: "Return low-level information on Docker objects", |
| 65 | Args: cli.RequiresMinArgs(1), |
| 66 | RunE: func(cmd *cobra.Command, args []string) error { |
| 67 | opts.ids = args |
| 68 | if cmd.Flags().Changed("type") && opts.objectType == "" { |
| 69 | return fmt.Errorf(`type is empty: must be one of "%s"`, strings.Join(allTypes, `", "`)) |
| 70 | } |
| 71 | return runInspect(cmd.Context(), dockerCLI, opts) |
| 72 | }, |
| 73 | // TODO(thaJeztah): should we consider adding completion for common object-types? (images, containers?) |
| 74 | ValidArgsFunction: completeObjectNames(dockerCLI), |
| 75 | DisableFlagsInUseLine: true, |
| 76 | } |
| 77 | |
| 78 | flags := cmd.Flags() |
| 79 | flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp) |
| 80 | flags.StringVar(&opts.objectType, "type", "", "Only inspect objects of the given type") |
| 81 | flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes if the type is container") |
| 82 | |
| 83 | _ = cmd.RegisterFlagCompletionFunc("type", completion.FromList(allTypes...)) |
| 84 | |
| 85 | return cmd |
| 86 | } |
| 87 | |
| 88 | func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error { |
| 89 | var elementSearcher inspect.GetRefFunc |
searching dependent graphs…