mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
explode when outputting to json
This commit is contained in:
parent
d6ff198d63
commit
0cb2ff5b2e
@ -52,6 +52,13 @@ func New() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if outputToJSON {
|
||||||
|
explodeOp := treeops.Operation{OperationType: treeops.Explode}
|
||||||
|
explodeNode := treeops.PathTreeNode{Operation: &explodeOp}
|
||||||
|
pipeOp := treeops.Operation{OperationType: treeops.Pipe}
|
||||||
|
pathNode = &treeops.PathTreeNode{Operation: &pipeOp, Lhs: pathNode, Rhs: &explodeNode}
|
||||||
|
}
|
||||||
|
|
||||||
matchingNodes, err := evaluate("-", pathNode)
|
matchingNodes, err := evaluate("-", pathNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -136,14 +136,6 @@ func printResults(matchingNodes *list.List, writer io.Writer) error {
|
|||||||
colorsEnabled = true
|
colorsEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//always explode anchors when printing json
|
|
||||||
if explodeAnchors || outputToJSON {
|
|
||||||
errorExploding := explode(matchingNodes)
|
|
||||||
if errorExploding != nil {
|
|
||||||
return errorExploding
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bufferedWriter := bufio.NewWriter(writer)
|
bufferedWriter := bufio.NewWriter(writer)
|
||||||
defer safelyFlush(bufferedWriter)
|
defer safelyFlush(bufferedWriter)
|
||||||
|
|
||||||
|
@ -24,9 +24,7 @@ type OperationType struct {
|
|||||||
// - documentIndex - retrieves document index, can be used with select
|
// - documentIndex - retrieves document index, can be used with select
|
||||||
// - mergeAppend (merges and appends arrays)
|
// - mergeAppend (merges and appends arrays)
|
||||||
// - mergeEmpty (sets only if the document is empty, do I do that now?)
|
// - mergeEmpty (sets only if the document is empty, do I do that now?)
|
||||||
// - updateStyle - not recursive
|
|
||||||
// - updateTag - not recursive
|
// - updateTag - not recursive
|
||||||
// - explodeAnchors
|
|
||||||
// - compare ??
|
// - compare ??
|
||||||
// - validate ??
|
// - validate ??
|
||||||
// - exists
|
// - exists
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nested alias
|
|
||||||
|
|
||||||
var explodeTest = []expressionScenario{
|
var explodeTest = []expressionScenario{
|
||||||
{
|
{
|
||||||
document: `{a: mike}`,
|
document: `{a: mike}`,
|
||||||
@ -37,6 +35,15 @@ var explodeTest = []expressionScenario{
|
|||||||
"D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n",
|
"D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
document: mergeDocSample,
|
||||||
|
expression: `.foo* | explode(explode(.)) | (. style="flow")`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[foo], (!!map)::{a: foo_a, thing: foo_thing, c: foo_c}\n",
|
||||||
|
"D0, P[foobarList], (!!map)::{b: bar_b, a: foo_a, thing: bar_thing, c: foobarList_c}\n",
|
||||||
|
"D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
document: `{f : {a: &a cat, b: &b {f: *a}, *a: *b}}`,
|
document: `{f : {a: &a cat, b: &b {f: *a}, *a: *b}}`,
|
||||||
expression: `explode(.f)`,
|
expression: `explode(.f)`,
|
||||||
|
Loading…
Reference in New Issue
Block a user