This commit is contained in:
Mike Farah
2021-12-21 16:19:27 +11:00
parent ae8df5ea87
commit 6bcbd873a6
6 changed files with 51 additions and 11 deletions
+5
View File
@@ -25,6 +25,7 @@ const (
PropsOutputFormat
CsvOutputFormat
TsvOutputFormat
XmlOutputFormat
)
func OutputFormatFromString(format string) (PrinterOutputFormat, error) {
@@ -39,6 +40,8 @@ func OutputFormatFromString(format string) (PrinterOutputFormat, error) {
return CsvOutputFormat, nil
case "tsv", "t":
return TsvOutputFormat, nil
case "xml", "x":
return XmlOutputFormat, nil
default:
return 0, fmt.Errorf("unknown format '%v' please use [yaml|json|props|csv|tsv]", format)
}
@@ -104,6 +107,8 @@ func (p *resultsPrinter) printNode(node *yaml.Node, writer io.Writer) error {
encoder = NewCsvEncoder(writer, '\t')
case YamlOutputFormat:
encoder = NewYamlEncoder(writer, p.indent, p.colorsEnabled)
case XmlOutputFormat:
encoder = NewXmlEncoder(writer, p.indent, "+", "+content")
}
return encoder.Encode(node)