1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Splat array is now the fallback instead of parsing int

This commit is contained in:
Mike Farah
2020-01-30 15:11:47 +11:00
parent 4a5bd0ff5b
commit 4dbe3636c2
3 changed files with 22 additions and 21 deletions

View File

@@ -3,7 +3,6 @@ package yqlib
import (
"strconv"
errors "github.com/pkg/errors"
yaml "gopkg.in/yaml.v3"
)
@@ -69,12 +68,15 @@ func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathSt
return n.recurseMap(value, head, tail, pathStack)
case yaml.SequenceNode:
log.Debug("its a sequence of %v things!", len(value.Content))
if n.navigationStrategy.GetPathParser().IsPathExpression(head) {
return n.splatArray(value, head, tail, pathStack)
var index, errorParsingIndex = strconv.ParseInt(head, 10, 64) // nolint
if errorParsingIndex == nil {
return n.recurseArray(value, index, head, tail, pathStack)
} else if head == "+" {
return n.appendArray(value, head, tail, pathStack)
}
return n.recurseArray(value, head, tail, pathStack)
return n.splatArray(value, head, tail, pathStack)
case yaml.AliasNode:
log.Debug("its an alias!")
DebugNode(value.Alias)
@@ -233,12 +235,7 @@ func (n *navigator) appendArray(value *yaml.Node, head string, tail []string, pa
return n.doTraverse(&newNode, head, tail, append(pathStack, len(value.Content)-1))
}
func (n *navigator) recurseArray(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
var index, err = strconv.ParseInt(head, 10, 64) // nolint
if err != nil {
return errors.Wrapf(err, "Error parsing array index '%v' for '%v'", head, pathStackToString(pathStack))
}
func (n *navigator) recurseArray(value *yaml.Node, index int64, head string, tail []string, pathStack []interface{}) error {
for int64(len(value.Content)) <= index {
value.Content = append(value.Content, &yaml.Node{Kind: guessKind(head, tail, 0)})
}

View File

@@ -55,7 +55,8 @@ func (p *pathParser) MatchesNextPathElement(nodeContext NodeContext, nodeKey str
navigator := NewDataNavigator(navigationStrategy)
err := navigator.Traverse(nodeContext.Node, p.ParsePath(path))
if err != nil {
log.Info(err.Error())
log.Error("Error deep recursing - ignoring")
log.Error(err.Error())
}
log.Debug("done deep recursing, found %v matches", len(navigationStrategy.GetVisitedNodes()))
return len(navigationStrategy.GetVisitedNodes()) > 0