1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

can set indent levels

This commit is contained in:
Mike Farah
2020-02-03 16:52:12 +11:00
parent 70b88fa778
commit 6840ea8c78
5 changed files with 84 additions and 25 deletions

View File

@@ -15,9 +15,12 @@ type yamlEncoder struct {
encoder *yaml.Encoder
}
func NewYamlEncoder(destination io.Writer) Encoder {
func NewYamlEncoder(destination io.Writer, indent int) Encoder {
var encoder = yaml.NewEncoder(destination)
encoder.SetIndent(2)
if indent < 0 {
indent = 0
}
encoder.SetIndent(indent)
return &yamlEncoder{encoder}
}
@@ -29,10 +32,15 @@ type jsonEncoder struct {
encoder *json.Encoder
}
func NewJsonEncoder(destination io.Writer, prettyPrint bool) Encoder {
func NewJsonEncoder(destination io.Writer, prettyPrint bool, indent int) Encoder {
var encoder = json.NewEncoder(destination)
var indentString = ""
for index := 0; index < indent; index++ {
indentString = indentString + " "
}
if prettyPrint {
encoder.SetIndent("", " ")
encoder.SetIndent("", indentString)
}
return &jsonEncoder{encoder}
}