This commit is contained in:
Mike Farah 2021-12-30 14:13:31 +11:00
parent d105efbcf1
commit 2c4bd03ec6
4 changed files with 12 additions and 4 deletions

View File

@ -24,13 +24,14 @@ type yamlEncoder struct {
colorise bool colorise bool
firstDoc bool firstDoc bool
printDocSeparators 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 { if indent < 0 {
indent = 0 indent = 0
} }
return &yamlEncoder{destination, indent, colorise, true, printDocSeparators} return &yamlEncoder{destination, indent, colorise, true, printDocSeparators, unwrapScalar}
} }
func (ye *yamlEncoder) PrintDocumentSeparator() error { func (ye *yamlEncoder) PrintDocumentSeparator() error {
if ye.printDocSeparators { if ye.printDocSeparators {

View File

@ -86,7 +86,7 @@ func getCommentsOperator(d *dataTreeNavigator, context Context, expressionNode *
var chompRegexp = regexp.MustCompile(`\n$`) var chompRegexp = regexp.MustCompile(`\n$`)
var output bytes.Buffer var output bytes.Buffer
var writer = bufio.NewWriter(&output) 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 { if err := encoder.PrintLeadingContent(candidate.LeadingContent); err != nil {
return Context{}, err return Context{}, err
} }

View File

@ -170,7 +170,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error {
} }
// what happens if I remove output format check? // 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) writer, err := p.printerWriter.GetWriter(nil)
if err != nil { if err != nil {
return err return err

View File

@ -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) { func readDocuments(reader io.Reader, filename string, fileIndex int, decoder Decoder) (*list.List, error) {
decoder.Init(reader) decoder.Init(reader)
inputList := list.New() inputList := list.New()