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))
| 299 | |
| 300 | // LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies |
| 301 | func 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 |
| 353 | func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) { |
no test coverage detected
searching dependent graphs…