(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string)
| 60 | } |
| 61 | |
| 62 | func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string) error { |
| 63 | apiClient := dockerCLI.Client() |
| 64 | |
| 65 | options := client.ImageRemoveOptions{ |
| 66 | Force: opts.force, |
| 67 | PruneChildren: !opts.noPrune, |
| 68 | } |
| 69 | |
| 70 | for _, v := range opts.platforms { |
| 71 | p, err := platforms.Parse(v) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | options.Platforms = append(options.Platforms, p) |
| 76 | } |
| 77 | |
| 78 | // TODO(thaJeztah): this logic can likely be simplified: do we want to print "not found" errors at all when using "force"? |
| 79 | fatalErr := false |
| 80 | var errs []error |
| 81 | for _, img := range images { |
| 82 | res, err := apiClient.ImageRemove(ctx, img, options) |
| 83 | if err != nil { |
| 84 | if !errdefs.IsNotFound(err) { |
| 85 | fatalErr = true |
| 86 | } |
| 87 | errs = append(errs, err) |
| 88 | } else { |
| 89 | for _, del := range res.Items { |
| 90 | if del.Deleted != "" { |
| 91 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Deleted:", del.Deleted) |
| 92 | } else { |
| 93 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Untagged:", del.Untagged) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if err := errors.Join(errs...); err != nil { |
| 100 | if !opts.force || fatalErr { |
| 101 | return err |
| 102 | } |
| 103 | _, _ = fmt.Fprintln(dockerCLI.Err(), err) |
| 104 | } |
| 105 | return nil |
| 106 | } |
no test coverage detected
searching dependent graphs…