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

Function decodeBlockAttrsSpec

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

Source from the content-addressed store, hash-verified

445}
446
447func decodeBlockAttrsSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) {
448 type content struct {
449 TypeName *string `hcl:"block_type"`
450 ElementType hcl.Expression `hcl:"element_type"`
451 Required *bool `hcl:"required"`
452 }
453
454 var args content
455 diags := gohcl.DecodeBody(body, nil, &args)
456 if diags.HasErrors() {
457 return errSpec, diags
458 }
459
460 spec := &hcldec.BlockAttrsSpec{
461 TypeName: impliedName,
462 }
463
464 if args.Required != nil {
465 spec.Required = *args.Required
466 }
467 if args.TypeName != nil {
468 spec.TypeName = *args.TypeName
469 }
470
471 var typeDiags hcl.Diagnostics
472 spec.ElementType, typeDiags = evalTypeExpr(args.ElementType)
473 diags = append(diags, typeDiags...)
474
475 if spec.TypeName == "" {
476 diags = append(diags, &hcl.Diagnostic{
477 Severity: hcl.DiagError,
478 Summary: "Missing block_type in block_attrs spec",
479 Detail: "The block_type attribute is required, to specify the block type name that is expected in an input HCL file.",
480 Subject: body.MissingItemRange().Ptr(),
481 })
482 return errSpec, diags
483 }
484
485 return spec, diags
486}
487
488func decodeLiteralSpec(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) {
489 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