hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

gohcl.EncodeIntoBody ignores optional elements #76

Closed mitchellh closed 5 years ago

mitchellh commented 5 years ago
type config struct {
    Other string `hcl:"other"`
    Field bool `hcl:"field,optional"`
}

input := &config{Field: true, Other: "hello"}
fw := hclwrite.NewEmptyFile()
gohcl.EncodeIntoBody(input, fw.Body())
println(string(fw.Bytes()))

The output only contains the required fields, does not contain the optional ones (though set).

mitchellh commented 5 years ago

My tag was missing : 😑(hcl"field" vs. hcl:"field")

So, this probably works.