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

Function decodeBlockSetSpec

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

Source from the content-addressed store, hash-verified

308}
309
310func decodeBlockSetSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) {
311 type content struct {
312 TypeName *string `hcl:"block_type"`
313 MinItems *int `hcl:"min_items"`
314 MaxItems *int `hcl:"max_items"`
315 Nested hcl.Body `hcl:",remain"`
316 }
317
318 var args content
319 diags := gohcl.DecodeBody(body, nil, &args)
320 if diags.HasErrors() {
321 return errSpec, diags
322 }
323
324 spec := &hcldec.BlockSetSpec{
325 TypeName: impliedName,
326 }
327
328 if args.MinItems != nil {
329 spec.MinItems = *args.MinItems
330 }
331 if args.MaxItems != nil {
332 spec.MaxItems = *args.MaxItems
333 }
334 if args.TypeName != nil {
335 spec.TypeName = *args.TypeName
336 }
337
338 nested, nestedDiags := decodeBlockNestedSpec(args.Nested)
339 diags = append(diags, nestedDiags...)
340 spec.Nested = nested
341
342 if spec.TypeName == "" {
343 diags = append(diags, &hcl.Diagnostic{
344 Severity: hcl.DiagError,
345 Summary: "Missing block_type in block_set spec",
346 Detail: "The block_type attribute is required, to specify the block type name that is expected in an input HCL file.",
347 Subject: body.MissingItemRange().Ptr(),
348 })
349 return errSpec, diags
350 }
351
352 return spec, diags
353}
354
355func decodeBlockMapSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) {
356 type content struct {

Callers 1

decodeSpecBlockFunction · 0.85

Calls 5

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

Tested by

no test coverage detected