From 95281eb2854772ab9aade91d881e8389619c5e8b Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:36:25 +0200 Subject: [PATCH] add working dir to LoadConfigFiles function to create ConfigDetails Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- cli/options.go | 6 +++--- loader/loader.go | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cli/options.go b/cli/options.go index 5de2f285..5d61516c 100644 --- a/cli/options.go +++ b/cli/options.go @@ -404,8 +404,8 @@ func (o *ProjectOptions) GetWorkingDir() (string, error) { } // ReadConfigFiles reads ConfigFiles and populates the content field -func (o ProjectOptions) ReadConfigFiles(ctx context.Context, options *ProjectOptions) (*types.ConfigDetails, error) { - config, err := loader.LoadConfigFiles(ctx, options.ConfigPaths, options.loadOptions...) +func (o *ProjectOptions) ReadConfigFiles(ctx context.Context, workingDir string, options *ProjectOptions) (*types.ConfigDetails, error) { + config, err := loader.LoadConfigFiles(ctx, options.ConfigPaths, workingDir, options.loadOptions...) if err != nil { return nil, err } @@ -477,7 +477,7 @@ func (o *ProjectOptions) prepare(ctx context.Context) (*types.ConfigDetails, err return &types.ConfigDetails{}, err } - configDetails, err := o.ReadConfigFiles(ctx, o) + configDetails, err := o.ReadConfigFiles(ctx, defaultDir, o) if err != nil { return configDetails, err } diff --git a/loader/loader.go b/loader/loader.go index 03c0cb26..21bb0ad1 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -30,6 +30,7 @@ import ( "strings" "github.com/compose-spec/compose-go/v2/consts" + "github.com/compose-spec/compose-go/v2/errdefs" interp "github.com/compose-spec/compose-go/v2/interpolation" "github.com/compose-spec/compose-go/v2/override" "github.com/compose-spec/compose-go/v2/paths" @@ -301,14 +302,15 @@ func parseYAML(decoder *yaml.Decoder) (map[string]interface{}, PostProcessor, er } // LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies -func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func(*Options)) (*types.ConfigDetails, error) { +func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir string, options ...func(*Options)) (*types.ConfigDetails, error) { if len(configFiles) < 1 { - return &types.ConfigDetails{}, errors.New("no files specified") + return &types.ConfigDetails{}, fmt.Errorf("no configuration file provided: %w", errdefs.ErrNotFound) } opts := &Options{} config := &types.ConfigDetails{ ConfigFiles: make([]types.ConfigFile, len(configFiles)), + WorkingDir: workingDir, } for _, op := range options { @@ -328,7 +330,7 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func( continue } if config.WorkingDir == "" { - config.WorkingDir = filepath.Dir(local) + config.WorkingDir = workingDir } abs, err := filepath.Abs(local)