| 374 | } |
| 375 | |
| 376 | func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) { |
| 377 | opts := []cli.ProjectOptionsFn{ |
| 378 | cli.WithWorkingDirectory(o.ProjectDir), |
| 379 | // First apply os.Environment, always win |
| 380 | cli.WithOsEnv, |
| 381 | } |
| 382 | |
| 383 | if _, present := os.LookupEnv("PWD"); !present { |
| 384 | if pwd, err := os.Getwd(); err != nil { |
| 385 | return nil, err |
| 386 | } else { |
| 387 | opts = append(opts, cli.WithEnv([]string{"PWD=" + pwd})) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | opts = append(opts, |
| 392 | // Load PWD/.env if present and no explicit --env-file has been set |
| 393 | cli.WithEnvFiles(o.EnvFiles...), |
| 394 | // read dot env file to populate project environment |
| 395 | cli.WithDotEnv, |
| 396 | // get compose file path set by COMPOSE_FILE |
| 397 | cli.WithConfigFileEnv, |
| 398 | // if none was selected, get default compose.yaml file from current dir or parent folder |
| 399 | cli.WithDefaultConfigPath, |
| 400 | // .. and then, a project directory != PWD maybe has been set so let's load .env file |
| 401 | cli.WithEnvFiles(o.EnvFiles...), //nolint:gocritic // intentionally applying cli.WithEnvFiles twice. |
| 402 | cli.WithDotEnv, //nolint:gocritic // intentionally applying cli.WithDotEnv twice. |
| 403 | // eventually COMPOSE_PROFILES should have been set |
| 404 | cli.WithDefaultProfiles(o.Profiles...), |
| 405 | cli.WithName(o.ProjectName), |
| 406 | ) |
| 407 | |
| 408 | return cli.NewProjectOptions(o.ConfigPaths, append(po, opts...)...) |
| 409 | } |
| 410 | |
| 411 | // PluginName is the name of the plugin |
| 412 | const PluginName = "compose" |