mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed delete splat
This commit is contained in:
parent
53a4a47ce3
commit
8be006fba4
@ -89,14 +89,23 @@ func (n *navigator) Delete(rootNode *yaml.Node, path []string) error {
|
|||||||
nodeToUpdate.Content = append(original[:index], original[index+1:]...)
|
nodeToUpdate.Content = append(original[:index], original[index+1:]...)
|
||||||
|
|
||||||
} else if nodeToUpdate.Kind == yaml.MappingNode {
|
} else if nodeToUpdate.Kind == yaml.MappingNode {
|
||||||
|
// need to delete in reverse...
|
||||||
|
matchingIndices := make([]int, 0)
|
||||||
_, errorVisiting := n.visitMatchingEntries(nodeToUpdate.Content, lastBit, func(indexInMap int) error {
|
_, errorVisiting := n.visitMatchingEntries(nodeToUpdate.Content, lastBit, func(indexInMap int) error {
|
||||||
nodeToUpdate.Content = append(original[:indexInMap], original[indexInMap+2:]...)
|
matchingIndices = append(matchingIndices, indexInMap)
|
||||||
|
n.log.Debug("matchingIndices %v", indexInMap)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
n.log.Debug("delete matching indices now")
|
||||||
|
n.log.Debug("%v", matchingIndices)
|
||||||
if errorVisiting != nil {
|
if errorVisiting != nil {
|
||||||
return errorVisiting
|
return errorVisiting
|
||||||
}
|
}
|
||||||
|
for i := len(matchingIndices) - 1; i >= 0; i-- {
|
||||||
|
indexToDelete := matchingIndices[i]
|
||||||
|
n.log.Debug("deleting index %v, %v", indexToDelete, nodeToUpdate.Content[indexToDelete].Value)
|
||||||
|
nodeToUpdate.Content = append(nodeToUpdate.Content[:indexToDelete], nodeToUpdate.Content[indexToDelete+2:]...)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +234,7 @@ func (n *navigator) visitMatchingEntries(contents []*yaml.Node, key string, visi
|
|||||||
// so keys are in the even indexes, values in odd.
|
// so keys are in the even indexes, values in odd.
|
||||||
for index := 0; index < len(contents); index = index + 2 {
|
for index := 0; index < len(contents); index = index + 2 {
|
||||||
content := contents[index]
|
content := contents[index]
|
||||||
|
n.log.Debug("index %v, checking %v", index, content.Value)
|
||||||
if n.matchesKey(key, content.Value) {
|
if n.matchesKey(key, content.Value) {
|
||||||
errorVisiting := visit(index)
|
errorVisiting := visit(index)
|
||||||
if errorVisiting != nil {
|
if errorVisiting != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user