(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts generateOptions, containers []string)
| 56 | } |
| 57 | |
| 58 | func runGenerate(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts generateOptions, containers []string) error { |
| 59 | _, _ = fmt.Fprintln(os.Stderr, "generate command is EXPERIMENTAL") |
| 60 | if len(containers) == 0 { |
| 61 | return fmt.Errorf("at least one container must be specified") |
| 62 | } |
| 63 | |
| 64 | backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | project, err := backend.Generate(ctx, api.GenerateOptions{ |
| 69 | Containers: containers, |
| 70 | ProjectName: opts.ProjectName, |
| 71 | }) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | var content []byte |
| 77 | switch opts.Format { |
| 78 | case "json": |
| 79 | content, err = project.MarshalJSON() |
| 80 | case "yaml": |
| 81 | content, err = project.MarshalYAML() |
| 82 | default: |
| 83 | return fmt.Errorf("unsupported format %q", opts.Format) |
| 84 | } |
| 85 | if err != nil { |
| 86 | return err |
| 87 | } |
| 88 | fmt.Println(string(content)) |
| 89 | |
| 90 | return nil |
| 91 | } |
no test coverage detected