hcl/hcldec/block_labels.go
Martin Atkins 0d6247f4cf hcldec: BlockLabelSpec decoding
A BlockLabelSpec can be placed in the nested spec structure of one of the
block specs to require and obtain labels on that block.

This is a more generic methodology than BlockMapSpec since it allows the
result to be a list or set with the labels inside the values, rather than
forcing all the label tuples to be unique and losing the ordering by
collapsing into a map structure.
2017-10-03 15:59:20 -07:00

22 lines
353 B
Go

package hcldec
import (
"github.com/hashicorp/hcl2/hcl"
)
type blockLabel struct {
Value string
Range hcl.Range
}
func labelsForBlock(block *hcl.Block) []blockLabel {
ret := make([]blockLabel, len(block.Labels))
for i := range block.Labels {
ret[i] = blockLabel{
Value: block.Labels[i],
Range: block.LabelRanges[i],
}
}
return ret
}