mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Refactor wip
This commit is contained in:
parent
ff5b23251b
commit
cf389bed4a
@ -154,9 +154,10 @@ func TestReadMergeAnchorsPrefixMatchCmd(t *testing.T) {
|
|||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
t.Error(result.Error)
|
t.Error(result.Error)
|
||||||
}
|
}
|
||||||
expectedOutput := `foobar.thing: ice
|
expectedOutput := `foobar.thirty: well beyond
|
||||||
foobar.thirty: well beyond
|
foobar.thing: ice
|
||||||
foobar.thirsty: yep`
|
foobar.thirsty: yep
|
||||||
|
`
|
||||||
test.AssertResult(t, expectedOutput, result.Output)
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,6 @@ foobarList:
|
|||||||
|
|
||||||
foobar:
|
foobar:
|
||||||
<<: *foo
|
<<: *foo
|
||||||
thing: ice
|
|
||||||
thirty: well beyond
|
thirty: well beyond
|
||||||
|
thing: ice
|
||||||
c: 3
|
c: 3
|
||||||
|
@ -3,6 +3,7 @@ b:
|
|||||||
c: things
|
c: things
|
||||||
d: whatever
|
d: whatever
|
||||||
things:
|
things:
|
||||||
|
borg: snorg
|
||||||
thing1:
|
thing1:
|
||||||
cat: 'fred'
|
cat: 'fred'
|
||||||
thing2:
|
thing2:
|
||||||
|
@ -37,6 +37,7 @@ func (n *navigator) doTraverse(value *yaml.Node, head string, path []string, pat
|
|||||||
DebugNode(value)
|
DebugNode(value)
|
||||||
return n.recurse(value, path[0], path[1:], pathStack)
|
return n.recurse(value, path[0], path[1:], pathStack)
|
||||||
}
|
}
|
||||||
|
log.Debug("should I visit?")
|
||||||
return n.navigationSettings.Visit(value, head, path, pathStack)
|
return n.navigationSettings.Visit(value, head, path, pathStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,16 +77,27 @@ func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
visited, errorVisiting := n.visitMatchingEntries(value, head, tail, pathStack, func(contents []*yaml.Node, indexInMap int) error {
|
traversedEntry := false
|
||||||
contents[indexInMap+1] = n.getOrReplace(contents[indexInMap+1], guessKind(tail, contents[indexInMap+1].Kind))
|
errorVisiting := n.visitMatchingEntries(value, head, tail, pathStack, func(contents []*yaml.Node, indexInMap int) error {
|
||||||
return n.doTraverse(contents[indexInMap+1], head, tail, append(pathStack, contents[indexInMap].Value))
|
|
||||||
|
log.Debug("should I traverse? %v", head)
|
||||||
|
DebugNode(value)
|
||||||
|
if n.navigationSettings.ShouldTraverse(contents[indexInMap+1], head, tail, append(pathStack, contents[indexInMap].Value)) == true {
|
||||||
|
log.Debug("yep!")
|
||||||
|
traversedEntry = true
|
||||||
|
contents[indexInMap+1] = n.getOrReplace(contents[indexInMap+1], guessKind(tail, contents[indexInMap+1].Kind))
|
||||||
|
return n.doTraverse(contents[indexInMap+1], head, tail, append(pathStack, contents[indexInMap].Value))
|
||||||
|
} else {
|
||||||
|
log.Debug("nope not traversing")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if errorVisiting != nil {
|
if errorVisiting != nil {
|
||||||
return errorVisiting
|
return errorVisiting
|
||||||
}
|
}
|
||||||
|
|
||||||
if visited || head == "*" || n.navigationSettings.AutoCreateMap(value, head, tail, pathStack) == false {
|
if traversedEntry == true || head == "*" || n.navigationSettings.AutoCreateMap(value, head, tail, pathStack) == false {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,33 +105,27 @@ func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pat
|
|||||||
value.Content = append(value.Content, &mapEntryKey)
|
value.Content = append(value.Content, &mapEntryKey)
|
||||||
mapEntryValue := yaml.Node{Kind: guessKind(tail, 0)}
|
mapEntryValue := yaml.Node{Kind: guessKind(tail, 0)}
|
||||||
value.Content = append(value.Content, &mapEntryValue)
|
value.Content = append(value.Content, &mapEntryValue)
|
||||||
log.Debug("adding new node %v", value.Content)
|
log.Debug("adding new node %v", head)
|
||||||
return n.doTraverse(&mapEntryValue, head, tail, append(pathStack, head))
|
return n.doTraverse(&mapEntryValue, head, tail, append(pathStack, head))
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to pass the node in, as it may be aliased
|
// need to pass the node in, as it may be aliased
|
||||||
type mapVisitorFn func(contents []*yaml.Node, index int) error
|
type mapVisitorFn func(contents []*yaml.Node, index int) error
|
||||||
|
|
||||||
func (n *navigator) visitDirectMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) (bool, error) {
|
func (n *navigator) visitDirectMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||||
var contents = node.Content
|
var contents = node.Content
|
||||||
visited := false
|
|
||||||
for index := 0; index < len(contents); index = index + 2 {
|
for index := 0; index < len(contents); index = index + 2 {
|
||||||
content := contents[index]
|
content := contents[index]
|
||||||
log.Debug("index %v, checking %v, %v", index, content.Value, content.Tag)
|
log.Debug("index %v, checking %v, %v", index, content.Value, content.Tag)
|
||||||
|
errorVisiting := visit(contents, index)
|
||||||
if n.navigationSettings.ShouldVisit(content, head, tail, pathStack) == true {
|
if errorVisiting != nil {
|
||||||
log.Debug("found a match! %v", content.Value)
|
return errorVisiting
|
||||||
errorVisiting := visit(contents, index)
|
|
||||||
if errorVisiting != nil {
|
|
||||||
return visited, errorVisiting
|
|
||||||
}
|
|
||||||
visited = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return visited, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *navigator) visitMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) (bool, error) {
|
func (n *navigator) visitMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||||
var contents = node.Content
|
var contents = node.Content
|
||||||
log.Debug("visitMatchingEntries %v", head)
|
log.Debug("visitMatchingEntries %v", head)
|
||||||
DebugNode(node)
|
DebugNode(node)
|
||||||
@ -127,20 +133,15 @@ func (n *navigator) visitMatchingEntries(node *yaml.Node, head string, tail []st
|
|||||||
// so keys are in the even indexes, values in odd.
|
// so keys are in the even indexes, values in odd.
|
||||||
// merge aliases are defined first, but we only want to traverse them
|
// merge aliases are defined first, but we only want to traverse them
|
||||||
// if we don't find a match directly on this node first.
|
// if we don't find a match directly on this node first.
|
||||||
visited, errorVisitedDirectEntries := n.visitDirectMatchingEntries(node, head, tail, pathStack, visit)
|
errorVisitedDirectEntries := n.visitDirectMatchingEntries(node, head, tail, pathStack, visit)
|
||||||
|
|
||||||
//TODO: crap we have to remember what we visited so we dont print the same key in the alias
|
if errorVisitedDirectEntries != nil || n.navigationSettings.FollowAlias(node, head, tail, pathStack) == false {
|
||||||
// eff
|
return errorVisitedDirectEntries
|
||||||
|
|
||||||
if errorVisitedDirectEntries != nil || visited == true || n.navigationSettings.FollowAlias(node, head, tail, pathStack) == false {
|
|
||||||
return visited, errorVisitedDirectEntries
|
|
||||||
}
|
}
|
||||||
// didnt find a match, lets check the aliases.
|
|
||||||
|
|
||||||
return n.visitAliases(contents, head, tail, pathStack, visit)
|
return n.visitAliases(contents, head, tail, pathStack, visit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *navigator) visitAliases(contents []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) (bool, error) {
|
func (n *navigator) visitAliases(contents []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||||
// merge aliases are defined first, but we only want to traverse them
|
// merge aliases are defined first, but we only want to traverse them
|
||||||
// if we don't find a match on this node first.
|
// if we don't find a match on this node first.
|
||||||
// traverse them backwards so that the last alias overrides the preceding.
|
// traverse them backwards so that the last alias overrides the preceding.
|
||||||
@ -156,36 +157,35 @@ func (n *navigator) visitAliases(contents []*yaml.Node, head string, tail []stri
|
|||||||
DebugNode(contents[index])
|
DebugNode(contents[index])
|
||||||
DebugNode(valueNode)
|
DebugNode(valueNode)
|
||||||
|
|
||||||
visitedAlias, errorInAlias := n.visitMatchingEntries(valueNode.Alias, head, tail, pathStack, visit)
|
errorInAlias := n.visitMatchingEntries(valueNode.Alias, head, tail, pathStack, visit)
|
||||||
if visitedAlias == true || errorInAlias != nil {
|
if errorInAlias != nil {
|
||||||
return visitedAlias, errorInAlias
|
return errorInAlias
|
||||||
}
|
}
|
||||||
} else if contents[index+1].Kind == yaml.SequenceNode {
|
} else if contents[index+1].Kind == yaml.SequenceNode {
|
||||||
// could be an array of aliases...
|
// could be an array of aliases...
|
||||||
visitedAliasSeq, errorVisitingAliasSeq := n.visitAliasSequence(contents[index+1].Content, head, tail, pathStack, visit)
|
errorVisitingAliasSeq := n.visitAliasSequence(contents[index+1].Content, head, tail, pathStack, visit)
|
||||||
if visitedAliasSeq == true || errorVisitingAliasSeq != nil {
|
if errorVisitingAliasSeq != nil {
|
||||||
return visitedAliasSeq, errorVisitingAliasSeq
|
return errorVisitingAliasSeq
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Debug("nope no matching aliases found")
|
return nil
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *navigator) visitAliasSequence(possibleAliasArray []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) (bool, error) {
|
func (n *navigator) visitAliasSequence(possibleAliasArray []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||||
// need to search this backwards too, so that aliases defined last override the preceding.
|
// need to search this backwards too, so that aliases defined last override the preceding.
|
||||||
for aliasIndex := len(possibleAliasArray) - 1; aliasIndex >= 0; aliasIndex = aliasIndex - 1 {
|
for aliasIndex := len(possibleAliasArray) - 1; aliasIndex >= 0; aliasIndex = aliasIndex - 1 {
|
||||||
child := possibleAliasArray[aliasIndex]
|
child := possibleAliasArray[aliasIndex]
|
||||||
if child.Kind == yaml.AliasNode {
|
if child.Kind == yaml.AliasNode {
|
||||||
log.Debug("found an alias")
|
log.Debug("found an alias")
|
||||||
DebugNode(child)
|
DebugNode(child)
|
||||||
visitedAlias, errorInAlias := n.visitMatchingEntries(child.Alias, head, tail, pathStack, visit)
|
errorInAlias := n.visitMatchingEntries(child.Alias, head, tail, pathStack, visit)
|
||||||
if visitedAlias == true || errorInAlias != nil {
|
if errorInAlias != nil {
|
||||||
return visitedAlias, errorInAlias
|
return errorInAlias
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *navigator) splatArray(value *yaml.Node, tail []string, pathStack []interface{}) error {
|
func (n *navigator) splatArray(value *yaml.Node, tail []string, pathStack []interface{}) error {
|
||||||
|
@ -2,7 +2,6 @@ package yqlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -16,15 +15,6 @@ func DeleteNavigationSettings(lastBit string) NavigationSettings {
|
|||||||
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
shouldVisit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
|
||||||
var prefixMatch = strings.TrimSuffix(head, "*")
|
|
||||||
if prefixMatch != head {
|
|
||||||
log.Debug("prefix match, %v", strings.HasPrefix(node.Value, prefixMatch))
|
|
||||||
return strings.HasPrefix(node.Value, prefixMatch)
|
|
||||||
}
|
|
||||||
log.Debug("equals match, %v", node.Value == head)
|
|
||||||
return node.Value == head
|
|
||||||
},
|
|
||||||
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
log.Debug("need to find %v in here", lastBit)
|
log.Debug("need to find %v in here", lastBit)
|
||||||
DebugNode(node)
|
DebugNode(node)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package yqlib
|
package yqlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
@ -16,15 +17,14 @@ type VisitedNode struct {
|
|||||||
type NavigationSettings interface {
|
type NavigationSettings interface {
|
||||||
FollowAlias(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
FollowAlias(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
||||||
AutoCreateMap(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
AutoCreateMap(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
||||||
ShouldVisit(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
|
||||||
Visit(node *yaml.Node, head string, tail []string, pathStack []interface{}) error
|
Visit(node *yaml.Node, head string, tail []string, pathStack []interface{}) error
|
||||||
|
ShouldTraverse(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
||||||
GetVisitedNodes() []*VisitedNode
|
GetVisitedNodes() []*VisitedNode
|
||||||
}
|
}
|
||||||
|
|
||||||
type NavigationSettingsImpl struct {
|
type NavigationSettingsImpl struct {
|
||||||
followAlias func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
followAlias func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
||||||
autoCreateMap func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
autoCreateMap func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
||||||
shouldVisit func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool
|
|
||||||
visit func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error
|
visit func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error
|
||||||
visitedNodes []*VisitedNode
|
visitedNodes []*VisitedNode
|
||||||
}
|
}
|
||||||
@ -51,26 +51,88 @@ func (ns *NavigationSettingsImpl) AutoCreateMap(node *yaml.Node, head string, ta
|
|||||||
return ns.autoCreateMap(node, head, tail, pathStack)
|
return ns.autoCreateMap(node, head, tail, pathStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NavigationSettingsImpl) Visit(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
func (ns *NavigationSettingsImpl) matchesNextPath(path string, candidate string) bool {
|
||||||
ns.visitedNodes = append(ns.visitedNodes, &VisitedNode{node, head, tail, pathStack})
|
var prefixMatch = strings.TrimSuffix(path, "*")
|
||||||
log.Debug("adding to visited nodes")
|
if prefixMatch != path {
|
||||||
return ns.visit(node, head, tail, pathStack)
|
log.Debug("prefix match, %v", strings.HasPrefix(candidate, prefixMatch))
|
||||||
}
|
return strings.HasPrefix(candidate, prefixMatch)
|
||||||
|
|
||||||
func (ns *NavigationSettingsImpl) ShouldVisit(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
|
||||||
if !ns.alreadyVisited(node) {
|
|
||||||
return ns.shouldVisit(node, head, tail, pathStack)
|
|
||||||
} else {
|
|
||||||
log.Debug("Skipping over %v as we have seen it already", node.Value)
|
|
||||||
}
|
}
|
||||||
return false
|
return candidate == path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NavigationSettingsImpl) alreadyVisited(node *yaml.Node) bool {
|
func (ns *NavigationSettingsImpl) ShouldTraverse(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
||||||
|
// we should traverse aliases (if enabled), but not visit them :/
|
||||||
|
if len(pathStack) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ns.alreadyVisited(pathStack) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
lastBit := fmt.Sprintf("%v", pathStack[len(pathStack)-1])
|
||||||
|
|
||||||
|
return (lastBit == "<<" && ns.FollowAlias(node, head, tail, pathStack)) || (lastBit != "<<" && ns.matchesNextPath(head, lastBit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *NavigationSettingsImpl) shouldVisit(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
||||||
|
// we should traverse aliases (if enabled), but not visit them :/
|
||||||
|
if len(pathStack) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ns.alreadyVisited(pathStack) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
lastBit := fmt.Sprintf("%v", pathStack[len(pathStack)-1])
|
||||||
|
// only visit aliases if its an exact match
|
||||||
|
return (lastBit == "<<" && head == "<<") || (lastBit != "<<" && ns.matchesNextPath(head, lastBit))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *NavigationSettingsImpl) Visit(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
|
if ns.shouldVisit(node, head, tail, pathStack) {
|
||||||
|
ns.visitedNodes = append(ns.visitedNodes, &VisitedNode{node, head, tail, pathStack})
|
||||||
|
log.Debug("adding to visited nodes, %v", head)
|
||||||
|
return ns.visit(node, head, tail, pathStack)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *NavigationSettingsImpl) alreadyVisited(pathStack []interface{}) bool {
|
||||||
|
log.Debug("looking for pathStack")
|
||||||
|
for _, val := range pathStack {
|
||||||
|
log.Debug("\t %v", val)
|
||||||
|
}
|
||||||
for _, candidate := range ns.visitedNodes {
|
for _, candidate := range ns.visitedNodes {
|
||||||
if candidate.Node.Value == node.Value {
|
candidatePathStack := candidate.PathStack
|
||||||
|
if patchStacksMatch(candidatePathStack, pathStack) {
|
||||||
|
log.Debug("paths match, already seen it")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
log.Debug("never seen it before!")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func patchStacksMatch(path1 []interface{}, path2 []interface{}) bool {
|
||||||
|
log.Debug("checking against path")
|
||||||
|
for _, val := range path1 {
|
||||||
|
log.Debug("\t %v", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(path1) != len(path2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for index, p1Value := range path1 {
|
||||||
|
|
||||||
|
p2Value := path2[index]
|
||||||
|
if p1Value != p2Value {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package yqlib
|
package yqlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,21 +13,6 @@ func ReadNavigationSettings() NavigationSettings {
|
|||||||
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
shouldVisit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
|
||||||
log.Debug("shouldVisit h: %v, actual: %v", head, node.Value)
|
|
||||||
if node.Value == "<<" {
|
|
||||||
log.Debug("its an alias, skip it")
|
|
||||||
// dont match alias keys, as we'll follow them instead
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
var prefixMatch = strings.TrimSuffix(head, "*")
|
|
||||||
if prefixMatch != head {
|
|
||||||
log.Debug("prefix match, %v", strings.HasPrefix(node.Value, prefixMatch))
|
|
||||||
return strings.HasPrefix(node.Value, prefixMatch)
|
|
||||||
}
|
|
||||||
log.Debug("equals match, %v", node.Value == head)
|
|
||||||
return node.Value == head
|
|
||||||
},
|
|
||||||
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package yqlib
|
package yqlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,15 +13,6 @@ func UpdateNavigationSettings(changesToApply *yaml.Node) NavigationSettings {
|
|||||||
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
autoCreateMap: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
shouldVisit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) bool {
|
|
||||||
var prefixMatch = strings.TrimSuffix(head, "*")
|
|
||||||
if prefixMatch != head {
|
|
||||||
log.Debug("prefix match, %v", strings.HasPrefix(node.Value, prefixMatch))
|
|
||||||
return strings.HasPrefix(node.Value, prefixMatch)
|
|
||||||
}
|
|
||||||
log.Debug("equals match, %v", node.Value == head)
|
|
||||||
return node.Value == head
|
|
||||||
},
|
|
||||||
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
visit: func(node *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||||
log.Debug("going to update")
|
log.Debug("going to update")
|
||||||
DebugNode(node)
|
DebugNode(node)
|
||||||
|
Loading…
Reference in New Issue
Block a user