(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts imageOptions, services []string)
| 60 | } |
| 61 | |
| 62 | func runImages(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts imageOptions, services []string) error { |
| 63 | projectName, err := opts.toProjectName(ctx, dockerCli) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | images, err := backend.Images(ctx, projectName, api.ImagesOptions{ |
| 73 | Services: services, |
| 74 | }) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | if opts.Quiet { |
| 80 | ids := []string{} |
| 81 | for _, img := range images { |
| 82 | id := img.ID |
| 83 | if i := strings.IndexRune(img.ID, ':'); i >= 0 { |
| 84 | id = id[i+1:] |
| 85 | } |
| 86 | if !slices.Contains(ids, id) { |
| 87 | ids = append(ids, id) |
| 88 | } |
| 89 | } |
| 90 | for _, img := range ids { |
| 91 | _, _ = fmt.Fprintln(dockerCli.Out(), img) |
| 92 | } |
| 93 | return nil |
| 94 | } |
| 95 | if opts.Format == "json" { |
| 96 | |
| 97 | type img struct { |
| 98 | ID string `json:"ID"` |
| 99 | ContainerName string `json:"ContainerName"` |
| 100 | Repository string `json:"Repository"` |
| 101 | Tag string `json:"Tag"` |
| 102 | Platform string `json:"Platform"` |
| 103 | Size int64 `json:"Size"` |
| 104 | Created *time.Time `json:"Created,omitempty"` |
| 105 | LastTagTime time.Time `json:"LastTagTime,omitzero"` |
| 106 | } |
| 107 | // Convert map to slice |
| 108 | var imageList []img |
| 109 | for ctr, i := range images { |
| 110 | lastTagTime := i.LastTagTime |
| 111 | imageList = append(imageList, img{ |
| 112 | ContainerName: ctr, |
| 113 | ID: i.ID, |
| 114 | Repository: i.Repository, |
| 115 | Tag: i.Tag, |
| 116 | Platform: platforms.Format(i.Platform), |
| 117 | Size: i.Size, |
| 118 | Created: i.Created, |
| 119 | LastTagTime: lastTagTime, |
no test coverage detected