(ctx context.Context, options api.GenerateOptions)
| 33 | ) |
| 34 | |
| 35 | func (s *composeService) Generate(ctx context.Context, options api.GenerateOptions) (*types.Project, error) { |
| 36 | res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{ |
| 37 | Filters: make(client.Filters).Add("name", options.Containers...), |
| 38 | All: true, |
| 39 | }) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | containers := res.Items |
| 44 | |
| 45 | containersByIds, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{ |
| 46 | Filters: make(client.Filters).Add("id", options.Containers...), |
| 47 | All: true, |
| 48 | }) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | |
| 53 | for _, ctr := range containersByIds.Items { |
| 54 | if !slices.ContainsFunc(containers, func(summary container.Summary) bool { |
| 55 | return summary.ID == ctr.ID |
| 56 | }) { |
| 57 | containers = append(containers, ctr) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if len(containers) == 0 { |
| 62 | return nil, fmt.Errorf("no container(s) found with the following name(s): %s", strings.Join(options.Containers, ",")) |
| 63 | } |
| 64 | |
| 65 | return s.createProjectFromContainers(containers, options.ProjectName) |
| 66 | } |
| 67 | |
| 68 | func (s *composeService) createProjectFromContainers(containers []container.Summary, projectName string) (*types.Project, error) { |
| 69 | project := &types.Project{} |
nothing calls this directly
no test coverage detected