mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 13:25:42 +00:00
Fixed scalar encoding for HCL
This commit is contained in:
parent
626624af7b
commit
ac2889c296
@ -43,6 +43,9 @@ func (he *hclEncoder) PrintLeadingContent(_ io.Writer, _ string) error {
|
|||||||
|
|
||||||
func (he *hclEncoder) Encode(writer io.Writer, node *CandidateNode) error {
|
func (he *hclEncoder) Encode(writer io.Writer, node *CandidateNode) error {
|
||||||
log.Debugf("I need to encode %v", NodeToString(node))
|
log.Debugf("I need to encode %v", NodeToString(node))
|
||||||
|
if node.Kind == ScalarNode {
|
||||||
|
return writeString(writer, node.Value+"\n")
|
||||||
|
}
|
||||||
|
|
||||||
f := hclwrite.NewEmptyFile()
|
f := hclwrite.NewEmptyFile()
|
||||||
body := f.Body()
|
body := f.Body()
|
||||||
@ -490,7 +493,7 @@ func (he *hclEncoder) encodeBlockIfMapping(body *hclwrite.Body, key string, valu
|
|||||||
// encodeNode encodes a CandidateNode directly to HCL, preserving style information
|
// encodeNode encodes a CandidateNode directly to HCL, preserving style information
|
||||||
func (he *hclEncoder) encodeNode(body *hclwrite.Body, node *CandidateNode) error {
|
func (he *hclEncoder) encodeNode(body *hclwrite.Body, node *CandidateNode) error {
|
||||||
if node.Kind != MappingNode {
|
if node.Kind != MappingNode {
|
||||||
return fmt.Errorf("HCL encoder expects a mapping at the root level")
|
return fmt.Errorf("HCL encoder expects a mapping at the root level, got %v", kindToString(node.Kind))
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(node.Content); i += 2 {
|
for i := 0; i < len(node.Content); i += 2 {
|
||||||
|
|||||||
@ -325,6 +325,14 @@ var hclFormatScenarios = []formatScenario{
|
|||||||
expected: "# Configuration\nport = 8080\n",
|
expected: "# Configuration\nport = 8080\n",
|
||||||
scenarioType: "roundtrip",
|
scenarioType: "roundtrip",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Roundtrip: extraction",
|
||||||
|
skipDoc: true,
|
||||||
|
input: simpleSample,
|
||||||
|
expression: ".shouty_message",
|
||||||
|
expected: "upper(message)\n",
|
||||||
|
scenarioType: "roundtrip",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Roundtrip: With templates, functions and arithmetic",
|
description: "Roundtrip: With templates, functions and arithmetic",
|
||||||
input: simpleSample,
|
input: simpleSample,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user