MCPcopy
hub / github.com/docker/compose / runGenerate

Function runGenerate

cmd/compose/generate.go:58–91  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts generateOptions, containers []string)

Source from the content-addressed store, hash-verified

56}
57
58func 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}

Callers 1

generateCommandFunction · 0.85

Calls 3

NewComposeServiceFunction · 0.92
MarshalJSONMethod · 0.80
GenerateMethod · 0.65

Tested by

no test coverage detected