mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Simplified when to visit a node
This commit is contained in:
parent
af5724ba29
commit
29521f2e3e
@ -32,15 +32,11 @@ func (n *navigator) Traverse(value *yaml.Node, path []string) error {
|
|||||||
|
|
||||||
func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
|
|
||||||
if value.Kind == yaml.ScalarNode {
|
|
||||||
return n.navigationStrategy.Visit(NewNodeContext(value, head, tail, pathStack))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debug("head %v", head)
|
log.Debug("head %v", head)
|
||||||
DebugNode(value)
|
DebugNode(value)
|
||||||
|
|
||||||
var errorDeepSplatting error
|
var errorDeepSplatting error
|
||||||
if head == "**" {
|
if head == "**" && value.Kind != yaml.ScalarNode {
|
||||||
if len(pathStack) == 0 || pathStack[len(pathStack)-1] != "<<" {
|
if len(pathStack) == 0 || pathStack[len(pathStack)-1] != "<<" {
|
||||||
errorDeepSplatting = n.recurse(value, head, tail, pathStack)
|
errorDeepSplatting = n.recurse(value, head, tail, pathStack)
|
||||||
}
|
}
|
||||||
@ -52,7 +48,7 @@ func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pat
|
|||||||
return errorDeepSplatting
|
return errorDeepSplatting
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tail) > 0 {
|
if len(tail) > 0 && value.Kind != yaml.ScalarNode {
|
||||||
log.Debugf("diving into %v", tail[0])
|
log.Debugf("diving into %v", tail[0])
|
||||||
DebugNode(value)
|
DebugNode(value)
|
||||||
return n.recurse(value, tail[0], tail[1:], pathStack)
|
return n.recurse(value, tail[0], tail[1:], pathStack)
|
||||||
@ -89,18 +85,12 @@ func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathSt
|
|||||||
log.Debug("its an alias!")
|
log.Debug("its an alias!")
|
||||||
DebugNode(value.Alias)
|
DebugNode(value.Alias)
|
||||||
if n.navigationStrategy.FollowAlias(NewNodeContext(value, head, tail, pathStack)) {
|
if n.navigationStrategy.FollowAlias(NewNodeContext(value, head, tail, pathStack)) {
|
||||||
|
log.Debug("following the alias")
|
||||||
if value.Alias.Kind == yaml.ScalarNode {
|
return n.recurse(value.Alias, head, tail, pathStack)
|
||||||
log.Debug("alias to a scalar")
|
|
||||||
return n.navigationStrategy.Visit(NewNodeContext(value.Alias, head, tail, pathStack))
|
|
||||||
} else {
|
|
||||||
log.Debug("following the alias")
|
|
||||||
return n.recurse(value.Alias, head, tail, pathStack)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return nil
|
return n.navigationStrategy.Visit(NewNodeContext(value, head, tail, pathStack))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user