(body hcl.Body)
| 502 | } |
| 503 | |
| 504 | func 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 | |
| 554 | func decodeTransformSpec(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) { |
| 555 | type content struct { |
no test coverage detected