Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
// KeyTag indicates that the value of the field should be part of
// the parent object block's key, not a property of that block
KeyTag string = "key"
// LabelTag is an alias for KeyTag, hcl v2 has renamed key to label.
LabelTag string = "label"

// SquashTag is attached to anonymous fields of a struct and indicates
// to the encoder to lift the fields of that value into the parent
Expand Down Expand Up @@ -220,7 +222,7 @@ func encodeMap(in reflect.Value) (ast.Node, []*ast.ObjectKey, error) {
}

// encodeStruct converts a struct type into an ast.ObjectType. An ast.ObjectKey
// may be returned if a KeyTag is present that should be used by a parent
// may be returned if a KeyTag/LabelTag is present that should be used by a parent
// ast.ObjectItem if this node is nested.
func encodeStruct(in reflect.Value) (ast.Node, []*ast.ObjectKey, error) {
l := in.NumField()
Expand Down Expand Up @@ -367,7 +369,7 @@ func extractFieldMeta(f reflect.StructField) (meta fieldMeta) {

for _, tag := range tags[1:] {
switch tag {
case KeyTag:
case KeyTag, LabelTag:
meta.key = true
case SquashTag:
meta.squash = true
Expand Down
4 changes: 4 additions & 0 deletions nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ func TestExtractFieldMeta(t *testing.T) {
`hcl:"bar,key"`,
fieldMeta{name: "bar", key: true},
},
{
`hcl:"bar,label"`,
fieldMeta{name: "bar", key: true},
},
{
`hcl:",squash"`,
fieldMeta{name: fieldName, squash: true},
Expand Down