(ctx context.Context, dockerCLI command.Cli, options imagesOptions)
| 86 | } |
| 87 | |
| 88 | func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions) (int, error) { |
| 89 | filters := options.filter.Value() |
| 90 | if options.matchName != "" { |
| 91 | filters.Add("reference", options.matchName) |
| 92 | } |
| 93 | |
| 94 | useTree, err := shouldUseTree(options) |
| 95 | if err != nil { |
| 96 | return 0, err |
| 97 | } |
| 98 | |
| 99 | listOpts := client.ImageListOptions{ |
| 100 | All: options.all, |
| 101 | Filters: filters, |
| 102 | Manifests: useTree, |
| 103 | } |
| 104 | |
| 105 | res, err := dockerCLI.Client().ImageList(ctx, listOpts) |
| 106 | if err != nil { |
| 107 | return 0, err |
| 108 | } |
| 109 | |
| 110 | images := res.Items |
| 111 | if !options.all { |
| 112 | if dangling, ok := filters["dangling"]; !ok || dangling["false"] { |
| 113 | images = slices.DeleteFunc(images, isDangling) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | format := options.format |
| 118 | if len(format) == 0 { |
| 119 | if len(dockerCLI.ConfigFile().ImagesFormat) > 0 && !options.quiet && !options.tree { |
| 120 | format = dockerCLI.ConfigFile().ImagesFormat |
| 121 | useTree = false |
| 122 | } else { |
| 123 | format = formatter.TableFormatKey |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if useTree { |
| 128 | return runTree(ctx, dockerCLI, treeOptions{ |
| 129 | images: images, |
| 130 | filters: filters, |
| 131 | expanded: options.tree, |
| 132 | }) |
| 133 | } |
| 134 | |
| 135 | imageCtx := formatter.ImageContext{ |
| 136 | Context: formatter.Context{ |
| 137 | Output: dockerCLI.Out(), |
| 138 | Format: formatter.NewImageFormat(format, options.quiet, options.showDigests), |
| 139 | Trunc: !options.noTrunc, |
| 140 | }, |
| 141 | Digest: options.showDigests, |
| 142 | } |
| 143 | if err := formatter.ImageWrite(imageCtx, images); err != nil { |
| 144 | return 0, err |
| 145 | } |
no test coverage detected
searching dependent graphs…