mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 17:36:59 +08:00
Added explode test
This commit is contained in:
+9
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user