2020-11-22 01:19:57 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
yaml "gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func createPathNodeFor(pathElement interface{}) *yaml.Node {
|
|
|
|
switch pathElement := pathElement.(type) {
|
|
|
|
case string:
|
|
|
|
return &yaml.Node{Kind: yaml.ScalarNode, Value: pathElement, Tag: "!!str"}
|
|
|
|
default:
|
|
|
|
return &yaml.Node{Kind: yaml.ScalarNode, Value: fmt.Sprintf("%v", pathElement), Tag: "!!int"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 23:18:53 +00:00
|
|
|
func getPathOperator(d *dataTreeNavigator, matchingNodes *list.List, expressionNode *ExpressionNode) (*list.List, error) {
|
2020-11-22 01:19:57 +00:00
|
|
|
log.Debugf("GetPath")
|
|
|
|
|
|
|
|
var results = list.New()
|
|
|
|
|
|
|
|
for el := matchingNodes.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
node := &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq"}
|
|
|
|
|
|
|
|
content := make([]*yaml.Node, len(candidate.Path))
|
|
|
|
for pathIndex := 0; pathIndex < len(candidate.Path); pathIndex++ {
|
|
|
|
path := candidate.Path[pathIndex]
|
|
|
|
content[pathIndex] = createPathNodeFor(path)
|
|
|
|
}
|
|
|
|
node.Content = content
|
2021-01-12 08:36:28 +00:00
|
|
|
result := candidate.CreateChild(nil, node)
|
|
|
|
results.PushBack(result)
|
2020-11-22 01:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|