From c442dbaa39879c19ab44cfc540c3018f72277ae2 Mon Sep 17 00:00:00 2001 From: Jeff Davis <14242442+JefeDavis@users.noreply.github.com> Date: Tue, 15 Jun 2021 09:47:49 -0500 Subject: [PATCH] fix: read all yaml files in directory for given path parameter (#97) Signed-off-by: Jeff Davis --- internal/instructions/config.go | 12 +++++++----- internal/instructions/yamlfile.go | 7 ------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/internal/instructions/config.go b/internal/instructions/config.go index 02c6ff8..4a8f5b5 100644 --- a/internal/instructions/config.go +++ b/internal/instructions/config.go @@ -134,7 +134,7 @@ func (cfg *Config) encodeNodes(nodes []*yaml.Node) (*bytes.Buffer, error) { func (cfg *Config) ReadAdHocPaths(i *Instructions) error { if cfg.Path != "" { - yf := YamlFiles{ + yfs := YamlFiles{ &YamlFile{ Name: "StdIn", Path: cfg.Path, @@ -142,15 +142,17 @@ func (cfg *Config) ReadAdHocPaths(i *Instructions) error { }, } - if err := yf.expandDirectories(); err != nil { + if err := yfs.expandDirectories(); err != nil { return fmt.Errorf("%w", err) } - if err := yf[0].readYamlFile(); err != nil { - return err + for _, yf := range yfs { + if err := yf.readYamlFile(); err != nil { + return err + } } - i.YamlFiles = append(i.YamlFiles, yf...) + i.YamlFiles = append(i.YamlFiles, yfs...) i.YamlFiles.mergeDuplicates() } diff --git a/internal/instructions/yamlfile.go b/internal/instructions/yamlfile.go index aed28b7..09e9e75 100644 --- a/internal/instructions/yamlfile.go +++ b/internal/instructions/yamlfile.go @@ -115,8 +115,6 @@ func (yfs *YamlFiles) expandDirectories() error { var paths []string - var removeItems []int - for i := 0; i <= len(y)-1; i++ { if !path.IsAbs(y[i].Path) { y[i].Path = path.Join(viper.GetString("instructionsDir"), y[i].Path) @@ -154,11 +152,6 @@ func (yfs *YamlFiles) expandDirectories() error { } } - for _, remove := range removeItems { - y[remove] = y[len(y)-1] - y = y[:len(y)-1] - } - *yfs = y return nil