-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_config_dir.go
56 lines (47 loc) · 1.33 KB
/
parser_config_dir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package factory
import (
"fmt"
"log"
"path/filepath"
"strings"
"github.com/hashicorp/hcl/v2"
)
// LoadFiles loads multiple configuration files from the specified paths
// and returns a slice of File objects along with any diagnostics encountered.
func (p *Parser) LoadFiles(paths []string) ([]*File, hcl.Diagnostics) {
var files []*File
var diags hcl.Diagnostics
for _, path := range paths {
var f *File
var fDiags hcl.Diagnostics
log.Printf("[DEBUG] loading config file: %s", path)
f, fDiags = p.LoadConfigFile(path)
diags = append(diags, fDiags...)
if f != nil {
files = append(files, f)
}
}
return files, diags
}
// This is used to find all the files in a module directory.
// It does this by looking for all files with the .hcl extension
// in the immediate directory.
func (p *Parser) DirFiles(dir string) (primary []string, diags hcl.Diagnostics) {
infos, err := p.fs.ReadDir(dir)
if err != nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Failed to read module directory",
Detail: fmt.Sprintf("Module directory %s does not exist or cannot be read.", dir),
})
return
}
for _, info := range infos {
name := info.Name()
if strings.HasSuffix(name, ".hcl") {
fullPath := filepath.Join(dir, name)
primary = append(primary, fullPath)
}
}
return primary, diags
}