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)
| 66 | // configuration file. An error diagnostic is returned if the given file |
| 67 | // cannot be read. |
| 68 | func (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. |
no test coverage detected