MCPcopy
hub / github.com/hashicorp/hcl / ParseHCLFile

Method ParseHCLFile

hclparse/parser.go:68–85  ·  view source on GitHub ↗

ParseHCLFile reads the given filename and parses it as a native-syntax HCL configuration file. An error diagnostic is returned if the given file cannot be read.

(filename string)

Source from the content-addressed store, hash-verified

66// configuration file. An error diagnostic is returned if the given file
67// cannot be read.
68func (p *Parser) ParseHCLFile(filename string) (*hcl.File, hcl.Diagnostics) {
69 if existing := p.files[filename]; existing != nil {
70 return existing, nil
71 }
72
73 src, err := os.ReadFile(filename)
74 if err != nil {
75 return nil, hcl.Diagnostics{
76 {
77 Severity: hcl.DiagError,
78 Summary: "Failed to read file",
79 Detail: fmt.Sprintf("The configuration file %q could not be read.", filename),
80 },
81 }
82 }
83
84 return p.ParseHCL(src, filename)
85}
86
87// ParseJSON parses the given JSON buffer (which is assumed to have been loaded
88// from the given filename) and returns the hcl.File object representing it.

Callers 4

LoadTestFileMethod · 0.80
loadSpecFileFunction · 0.80
parseVarsFileFunction · 0.80
realmainFunction · 0.80

Calls 1

ParseHCLMethod · 0.95

Tested by

no test coverage detected