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

Function decodeDefaultSpec

cmd/hcldec/spec.go:504–552  ·  view source on GitHub ↗
(body hcl.Body)

Source from the content-addressed store, hash-verified

502}
503
504func decodeDefaultSpec(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) {
505 content, diags := body.Content(specSchemaUnlabelled)
506
507 if len(content.Blocks) == 0 {
508 if diags.HasErrors() {
509 // If we already have errors then they probably explain
510 // why we have no blocks, so we'll skip our additional
511 // error message added below.
512 return errSpec, diags
513 }
514
515 diags = append(diags, &hcl.Diagnostic{
516 Severity: hcl.DiagError,
517 Summary: "Missing spec block",
518 Detail: "A default block must have at least one nested spec, each specifying a possible outcome.",
519 Subject: body.MissingItemRange().Ptr(),
520 })
521 return errSpec, diags
522 }
523
524 if len(content.Blocks) == 1 && !diags.HasErrors() {
525 diags = append(diags, &hcl.Diagnostic{
526 Severity: hcl.DiagWarning,
527 Summary: "Useless default block",
528 Detail: "A default block with only one spec is equivalent to using that spec alone.",
529 Subject: &content.Blocks[1].DefRange,
530 })
531 }
532
533 var spec hcldec.Spec
534 for _, block := range content.Blocks {
535 candidateSpec, candidateDiags := decodeSpecBlock(block)
536 diags = append(diags, candidateDiags...)
537 if candidateDiags.HasErrors() {
538 continue
539 }
540
541 if spec == nil {
542 spec = candidateSpec
543 } else {
544 spec = &hcldec.DefaultSpec{
545 Primary: spec,
546 Default: candidateSpec,
547 }
548 }
549 }
550
551 return spec, diags
552}
553
554func decodeTransformSpec(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) {
555 type content struct {

Callers 1

decodeSpecBlockFunction · 0.85

Calls 5

decodeSpecBlockFunction · 0.85
HasErrorsMethod · 0.80
PtrMethod · 0.80
ContentMethod · 0.65
MissingItemRangeMethod · 0.65

Tested by

no test coverage detected