From 2c4bd03ec60201227fb96e180c160466ca3785ce Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Thu, 30 Dec 2021 14:13:31 +1100 Subject: [PATCH] wip --- pkg/yqlib/encoder.go | 5 +++-- pkg/yqlib/operator_comments.go | 2 +- pkg/yqlib/printer.go | 2 +- pkg/yqlib/utils.go | 7 +++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/yqlib/encoder.go b/pkg/yqlib/encoder.go index 80b0380f..b1d83d61 100644 --- a/pkg/yqlib/encoder.go +++ b/pkg/yqlib/encoder.go @@ -24,13 +24,14 @@ type yamlEncoder struct { colorise bool firstDoc bool printDocSeparators bool + unwrapScalar bool } -func NewYamlEncoder(destination io.Writer, indent int, colorise bool, printDocSeparators bool) Encoder { +func NewYamlEncoder(destination io.Writer, indent int, colorise bool, printDocSeparators bool, unwrapScalar bool) Encoder { if indent < 0 { indent = 0 } - return &yamlEncoder{destination, indent, colorise, true, printDocSeparators} + return &yamlEncoder{destination, indent, colorise, true, printDocSeparators, unwrapScalar} } func (ye *yamlEncoder) PrintDocumentSeparator() error { if ye.printDocSeparators { diff --git a/pkg/yqlib/operator_comments.go b/pkg/yqlib/operator_comments.go index 375cfb53..7b11c1c0 100644 --- a/pkg/yqlib/operator_comments.go +++ b/pkg/yqlib/operator_comments.go @@ -86,7 +86,7 @@ func getCommentsOperator(d *dataTreeNavigator, context Context, expressionNode * var chompRegexp = regexp.MustCompile(`\n$`) var output bytes.Buffer var writer = bufio.NewWriter(&output) - var encoder = NewYamlEncoder(writer, 2, false, true) + var encoder = NewYamlEncoder(writer, 2, false, true, false) if err := encoder.PrintLeadingContent(candidate.LeadingContent); err != nil { return Context{}, err } diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index 9b3e4630..d5fedccc 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -170,7 +170,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { } // what happens if I remove output format check? - if p.appendixReader != nil && p.outputFormat == YamlOutputFormat { + if p.appendixReader != nil { writer, err := p.printerWriter.GetWriter(nil) if err != nil { return err diff --git a/pkg/yqlib/utils.go b/pkg/yqlib/utils.go index 47871f05..3914e967 100644 --- a/pkg/yqlib/utils.go +++ b/pkg/yqlib/utils.go @@ -70,6 +70,13 @@ func processReadStream(reader *bufio.Reader) (io.Reader, string, error) { } } +func explodeNodes(nodes *list.List) (*list.List, error) { + explodeOp := Operation{OperationType: explodeOpType} + explodeNode := ExpressionNode{Operation: &explodeOp} + context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: nodes}, &explodeNode) + return context.MatchingNodes, err +} + func readDocuments(reader io.Reader, filename string, fileIndex int, decoder Decoder) (*list.List, error) { decoder.Init(reader) inputList := list.New()