Skip to content

Commit

Permalink
refactor(GH-33): pass the whole config.Config instead of just func
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Dec 3, 2022
1 parent fbf7c60 commit 5329fd2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/travelgrunt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {
log.Fatalf("failed to load travelgrunt config: %s", err.Error())
}

entries, paths, err := directory.Collect(rootPath, cfg.IncludeFn)
entries, paths, err := directory.Collect(rootPath, cfg)

if err != nil {
log.Fatalf("failed to collect Terragrunt project directories: %s", err.Error())
Expand Down
6 changes: 4 additions & 2 deletions pkg/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"os"
"path/filepath"
"strings"

"github.com/ivanilves/travelgrunt/pkg/config"
)

func isHidden(d os.DirEntry) bool {
return d.IsDir() && string(d.Name()[0]) == "."
}

// Collect gets a list of directory path entries containing file "terragrunt.hcl"
func Collect(rootPath string, includeFn func(os.DirEntry) bool) (entries map[string]string, paths []string, err error) {
func Collect(rootPath string, cfg config.Config) (entries map[string]string, paths []string, err error) {
entries = make(map[string]string, 0)
paths = make([]string, 0)

Expand All @@ -25,7 +27,7 @@ func Collect(rootPath string, includeFn func(os.DirEntry) bool) (entries map[str
return filepath.SkipDir
}

if includeFn(d) {
if cfg.IncludeFn(d) {
abs := filepath.Dir(path)
rel := strings.TrimPrefix(abs, rootPath+"/")

Expand Down
2 changes: 1 addition & 1 deletion pkg/directory/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCollect(t *testing.T) {
}

for path, expectedSuccess := range testCases {
entries, paths, err := Collect(path, cfg.IncludeFn)
entries, paths, err := Collect(path, cfg)

if expectedSuccess {
assert.Greater(len(entries), 0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/directory/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
func mockTree() Tree {
cfg := config.DefaultConfig()

_, paths, _ := directory.Collect(fixturePath, cfg.IncludeFn)
_, paths, _ := directory.Collect(fixturePath, cfg)

return NewTree(paths)
}
Expand Down

0 comments on commit 5329fd2

Please sign in to comment.