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

Function decodeAttrSpec

cmd/hcldec/spec.go:193–232  ·  view source on GitHub ↗
(body hcl.Body, impliedName string)

Source from the content-addressed store, hash-verified

191}
192
193func decodeAttrSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) {
194 type content struct {
195 Name *string `hcl:"name"`
196 Type hcl.Expression `hcl:"type"`
197 Required *bool `hcl:"required"`
198 }
199
200 var args content
201 diags := gohcl.DecodeBody(body, nil, &args)
202 if diags.HasErrors() {
203 return errSpec, diags
204 }
205
206 spec := &hcldec.AttrSpec{
207 Name: impliedName,
208 }
209
210 if args.Required != nil {
211 spec.Required = *args.Required
212 }
213 if args.Name != nil {
214 spec.Name = *args.Name
215 }
216
217 var typeDiags hcl.Diagnostics
218 spec.Type, typeDiags = evalTypeExpr(args.Type)
219 diags = append(diags, typeDiags...)
220
221 if spec.Name == "" {
222 diags = append(diags, &hcl.Diagnostic{
223 Severity: hcl.DiagError,
224 Summary: "Missing name in attribute spec",
225 Detail: "The name attribute is required, to specify the attribute name that is expected in an input HCL file.",
226 Subject: body.MissingItemRange().Ptr(),
227 })
228 return errSpec, diags
229 }
230
231 return spec, diags
232}
233
234func decodeBlockSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) {
235 type content struct {

Callers 1

decodeSpecBlockFunction · 0.85

Calls 5

DecodeBodyFunction · 0.92
evalTypeExprFunction · 0.85
HasErrorsMethod · 0.80
PtrMethod · 0.80
MissingItemRangeMethod · 0.65

Tested by

no test coverage detected