Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Apr 5, 2024
1 parent ce5b85b commit 23d6b3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/leg100/pug/internal/logging"
"github.com/leg100/pug/internal/resource"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -61,7 +62,7 @@ func (m *Module) LogValue() slog.Value {
//
// (a) will only succeed if the module has already been initialized, i.e. terraform
// init has been run, whereas (b) is necessary if it has not.
func findModules(parent string) (modules []string, err error) {
func findModules(logger *logging.Logger, parent string) (modules []string, err error) {
found := make(map[string]struct{})
walkfn := func(path string, d fs.DirEntry, walkerr error) error {
// skip directories that have already been identified as containing a
Expand Down Expand Up @@ -91,7 +92,7 @@ func findModules(parent string) (modules []string, err error) {
// so this is what is used even though no writing is performed.
file, diags := hclwrite.ParseConfig(cfg, path, hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
slog.Error("reloading modules: parsing hcl", "path", path, "error", diags)
logger.Error("reloading modules: parsing hcl", "path", path, "error", diags)
return nil
}
for _, block := range file.Body().Blocks() {
Expand Down
3 changes: 2 additions & 1 deletion internal/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package module
import (
"testing"

"github.com/leg100/pug/internal/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFindModules(t *testing.T) {
got, err := findModules("../testdata/configs")
got, err := findModules(logging.NewLogger("info"), "../testdata/configs")
require.NoError(t, err)

assert.Equal(t, 7, len(got))
Expand Down
2 changes: 1 addition & 1 deletion internal/module/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *Service) Reload() error {
removed []string
)

found, err := findModules(s.workdir)
found, err := findModules(s.logger, s.workdir)
if err != nil {
return err
}
Expand Down

0 comments on commit 23d6b3c

Please sign in to comment.