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

Function LoadConfigFiles

loader/loader.go:301–350  ·  view source on GitHub ↗

LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies

(ctx context.Context, configFiles []string, workingDir string, options ...func(*Options))

Source from the content-addressed store, hash-verified

299
300// LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies
301func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir string, options ...func(*Options)) (*types.ConfigDetails, error) {
302 if len(configFiles) < 1 {
303 return &types.ConfigDetails{}, fmt.Errorf("no configuration file provided: %w", errdefs.ErrNotFound)
304 }
305
306 opts := &Options{}
307 config := &types.ConfigDetails{
308 ConfigFiles: make([]types.ConfigFile, len(configFiles)),
309 }
310
311 for _, op := range options {
312 op(opts)
313 }
314 opts.ResourceLoaders = append(opts.ResourceLoaders, localResourceLoader{})
315
316 for i, p := range configFiles {
317 if p == "-" {
318 config.ConfigFiles[i] = types.ConfigFile{
319 Filename: p,
320 }
321 continue
322 }
323
324 for _, loader := range opts.ResourceLoaders {
325 _, isLocalResourceLoader := loader.(localResourceLoader)
326 if !loader.Accept(p) {
327 continue
328 }
329 local, err := loader.Load(ctx, p)
330 if err != nil {
331 return nil, err
332 }
333 if config.WorkingDir == "" && !isLocalResourceLoader {
334 config.WorkingDir = filepath.Dir(local)
335 }
336 abs, err := filepath.Abs(local)
337 if err != nil {
338 abs = local
339 }
340 config.ConfigFiles[i] = types.ConfigFile{
341 Filename: abs,
342 }
343 break
344 }
345 }
346 if config.WorkingDir == "" {
347 config.WorkingDir = workingDir
348 }
349 return config, nil
350}
351
352// LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
353func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {

Callers 1

ReadConfigFilesMethod · 0.92

Calls 3

AcceptMethod · 0.65
LoadMethod · 0.65
DirMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…