newImagesCommand creates a new `docker images` command
(dockerCLI command.Cli)
| 35 | |
| 36 | // newImagesCommand creates a new `docker images` command |
| 37 | func newImagesCommand(dockerCLI command.Cli) *cobra.Command { |
| 38 | options := imagesOptions{filter: opts.NewFilterOpt()} |
| 39 | |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "images [OPTIONS] [REPOSITORY[:TAG]]", |
| 42 | Short: "List images", |
| 43 | Args: cli.RequiresMaxArgs(1), |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | if len(args) > 0 { |
| 46 | options.matchName = args[0] |
| 47 | } |
| 48 | numImages, err := runImages(cmd.Context(), dockerCLI, options) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | if numImages == 0 && options.matchName != "" && cmd.CalledAs() == "images" { |
| 53 | printAmbiguousHint(dockerCLI.Err(), options.matchName) |
| 54 | } |
| 55 | return nil |
| 56 | }, |
| 57 | Annotations: map[string]string{ |
| 58 | "category-top": "7", |
| 59 | "aliases": "docker image ls, docker image list, docker images", |
| 60 | }, |
| 61 | DisableFlagsInUseLine: true, |
| 62 | ValidArgsFunction: completion.ImageNamesWithBase(dockerCLI, 1), |
| 63 | } |
| 64 | |
| 65 | flags := cmd.Flags() |
| 66 | |
| 67 | flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only show image IDs") |
| 68 | flags.BoolVarP(&options.all, "all", "a", false, "Show all images (default hides intermediate and dangling images)") |
| 69 | flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") |
| 70 | flags.BoolVar(&options.showDigests, "digests", false, "Show digests") |
| 71 | flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) |
| 72 | flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") |
| 73 | |
| 74 | flags.BoolVar(&options.tree, "tree", false, "List multi-platform images as a tree (EXPERIMENTAL)") |
| 75 | flags.SetAnnotation("tree", "version", []string{"1.47"}) |
| 76 | flags.SetAnnotation("tree", "experimentalCLI", nil) |
| 77 | |
| 78 | return cmd |
| 79 | } |
| 80 | |
| 81 | func newListCommand(dockerCLI command.Cli) *cobra.Command { |
| 82 | cmd := *newImagesCommand(dockerCLI) |
searching dependent graphs…