yq/pkg/yqlib/read_navigation_strategy.go

34 lines
861 B
Go
Raw Normal View History

2019-12-25 01:11:04 +00:00
package yqlib
2020-02-07 05:32:39 +00:00
func ReadNavigationStrategy(deeplyTraverseArrays bool) NavigationStrategy {
2019-12-28 07:19:37 +00:00
return &NavigationStrategyImpl{
visitedNodes: []*NodeContext{},
pathParser: NewPathParser(),
2019-12-28 07:19:37 +00:00
followAlias: func(nodeContext NodeContext) bool {
2019-12-25 01:11:04 +00:00
return true
},
2019-12-28 07:19:37 +00:00
autoCreateMap: func(nodeContext NodeContext) bool {
2019-12-25 01:11:04 +00:00
return false
},
2019-12-28 07:19:37 +00:00
visit: func(nodeContext NodeContext) error {
2019-12-25 01:11:04 +00:00
return nil
},
2020-02-07 05:32:39 +00:00
shouldDeeplyTraverse: func(nodeContext NodeContext) bool {
var isInArray = false
if len(nodeContext.PathStack) > 0 {
var lastElement = nodeContext.PathStack[len(nodeContext.PathStack)-1]
switch lastElement.(type) {
case int:
isInArray = true
default:
isInArray = false
}
}
return deeplyTraverseArrays || !isInArray
},
2020-06-10 23:40:59 +00:00
shouldOnlyDeeplyVisitLeaves: func(nodeContext NodeContext) bool {
return true
},
2019-12-25 01:11:04 +00:00
}
}