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

Function DecodeFile

hclsimple/hclsimple.go:88–110  ·  view source on GitHub ↗

DecodeFile is a wrapper around Decode that first reads the given filename from disk. See the Decode documentation for more information.

(filename string, ctx *hcl.EvalContext, target interface{})

Source from the content-addressed store, hash-verified

86// DecodeFile is a wrapper around Decode that first reads the given filename
87// from disk. See the Decode documentation for more information.
88func DecodeFile(filename string, ctx *hcl.EvalContext, target interface{}) error {
89 src, err := os.ReadFile(filename)
90 if err != nil {
91 if os.IsNotExist(err) {
92 return hcl.Diagnostics{
93 {
94 Severity: hcl.DiagError,
95 Summary: "Configuration file not found",
96 Detail: fmt.Sprintf("The configuration file %s does not exist.", filename),
97 },
98 }
99 }
100 return hcl.Diagnostics{
101 {
102 Severity: hcl.DiagError,
103 Summary: "Failed to read configuration",
104 Detail: fmt.Sprintf("Can't read %s: %s.", filename, err),
105 },
106 }
107 }
108
109 return Decode(filename, src, ctx, target)
110}

Callers 1

TestDecodeFileFunction · 0.92

Calls 1

DecodeFunction · 0.70

Tested by 1

TestDecodeFileFunction · 0.74