Added explode test

This commit is contained in:
Mike Farah
2020-02-05 15:08:13 +11:00
parent dc13fa99f7
commit b7dd3e8e0a
2 changed files with 50 additions and 2 deletions
+9 -2
View File
@@ -103,6 +103,7 @@ func writeString(writer io.Writer, txt string) error {
}
func explode(matchingNodes []*yqlib.NodeContext) error {
for _, nodeContext := range matchingNodes {
var targetNode = yaml.Node{Kind: yaml.MappingNode}
explodedNodes, errorRetrieving := lib.Get(nodeContext.Node, "**")
@@ -112,7 +113,10 @@ func explode(matchingNodes []*yqlib.NodeContext) error {
for _, matchingNode := range explodedNodes {
mergePath := lib.MergePathStackToString(matchingNode.PathStack, appendFlag)
updateCommand := yqlib.UpdateCommand{Command: "update", Path: mergePath, Value: matchingNode.Node, Overwrite: overwriteFlag}
lib.Update(&targetNode, updateCommand, true)
errorUpdating := lib.Update(&targetNode, updateCommand, true)
if errorUpdating != nil {
return errorUpdating
}
}
nodeContext.Node = &targetNode
}
@@ -126,7 +130,10 @@ func printResults(matchingNodes []*yqlib.NodeContext, writer io.Writer) error {
//always explode anchors when printing json
if explodeAnchors || outputToJSON {
explode(matchingNodes)
errorExploding := explode(matchingNodes)
if errorExploding != nil {
return errorExploding
}
}
bufferedWriter := bufio.NewWriter(writer)