MCPcopy Create free account
hub / github.com/compose-spec/compose-go / ReadConfigFiles

Method ReadConfigFiles

cli/options.go:433–464  ·  view source on GitHub ↗

ReadConfigFiles reads ConfigFiles and populates the content field

(ctx context.Context, workingDir string, options *ProjectOptions)

Source from the content-addressed store, hash-verified

431
432// ReadConfigFiles reads ConfigFiles and populates the content field
433func (o *ProjectOptions) ReadConfigFiles(ctx context.Context, workingDir string, options *ProjectOptions) (*types.ConfigDetails, error) {
434 config, err := loader.LoadConfigFiles(ctx, options.ConfigPaths, workingDir, options.loadOptions...)
435 if err != nil {
436 return nil, err
437 }
438 configs := make([][]byte, len(config.ConfigFiles))
439
440 for i, c := range config.ConfigFiles {
441 var err error
442 var b []byte
443 if c.IsStdin() {
444 b, err = io.ReadAll(os.Stdin)
445 if err != nil {
446 return nil, err
447 }
448 } else {
449 f, err := filepath.Abs(c.Filename)
450 if err != nil {
451 return nil, err
452 }
453 b, err = os.ReadFile(f)
454 if err != nil {
455 return nil, err
456 }
457 }
458 configs[i] = b
459 }
460 for i, c := range configs {
461 config.ConfigFiles[i].Content = c
462 }
463 return config, nil
464}
465
466// LoadProject loads compose file according to options and bind to types.Project go structs
467func (o *ProjectOptions) LoadProject(ctx context.Context) (*types.Project, error) {

Callers 1

prepareMethod · 0.95

Calls 2

LoadConfigFilesFunction · 0.92
IsStdinMethod · 0.80

Tested by

no test coverage detected