yq/pkg/yqlib/treeops/operator_collect.go

34 lines
841 B
Go
Raw Normal View History

2020-10-17 11:10:47 +00:00
package treeops
import (
2020-10-21 01:54:58 +00:00
"container/list"
2020-10-17 11:10:47 +00:00
"gopkg.in/yaml.v3"
)
2020-10-21 01:54:58 +00:00
func CollectOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNode) (*list.List, error) {
2020-10-17 11:10:47 +00:00
log.Debugf("-- collectOperation")
2020-10-21 01:54:58 +00:00
var results = list.New()
2020-10-17 11:10:47 +00:00
node := &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq"}
var document uint = 0
var path []interface{}
for el := matchMap.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
log.Debugf("Collecting %v", NodeToString(candidate))
if path == nil && candidate.Path != nil && len(candidate.Path) > 1 {
path = candidate.Path[:len(candidate.Path)-1]
document = candidate.Document
}
node.Content = append(node.Content, candidate.Node)
}
collectC := &CandidateNode{Node: node, Document: document, Path: path}
2020-10-21 01:54:58 +00:00
results.PushBack(collectC)
2020-10-17 11:10:47 +00:00
return results, nil
}