Skip to content

Commit

Permalink
introduce WithConfigFileEnv to get config file paths from environment
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed May 17, 2021
1 parent 6dcd3d1 commit 3ae9674
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ func WithWorkingDirectory(wd string) ProjectOptionsFn {
}
}

// WithConfigFileEnv allow to set compose config file paths by COMPOSE_FILE environment variable
func WithConfigFileEnv(o *ProjectOptions) error {
sep := o.Environment[ComposeFileSeparator]
if sep == "" {
sep = string(os.PathListSeparator)
}
f := o.Environment[ComposeFilePath]
if f != "" {
paths, err := absolutePaths(strings.Split(f, sep), o.WorkingDir)
o.ConfigPaths = paths
return err
}
return nil
}

// WithDefaultConfigPath searches for default config files from working directory
func WithDefaultConfigPath(o *ProjectOptions) error {
if len(o.ConfigPaths) > 0 {
Expand Down Expand Up @@ -285,15 +300,6 @@ func getConfigPathsFromOptions(options *ProjectOptions) ([]string, error) {
return absolutePaths(options.ConfigPaths, pwd)
}

sep := options.Environment[ComposeFileSeparator]
if sep == "" {
sep = string(os.PathListSeparator)
}
f := options.Environment[ComposeFilePath]
if f != "" {
return absolutePaths(strings.Split(f, sep), pwd)
}

return nil, errors.New("no configuration file provided")
}

Expand Down

0 comments on commit 3ae9674

Please sign in to comment.