mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
40 lines
862 B
Go
40 lines
862 B
Go
|
package yqlib
|
||
|
|
||
|
import (
|
||
|
"container/list"
|
||
|
|
||
|
yaml "gopkg.in/yaml.v3"
|
||
|
)
|
||
|
|
||
|
func kindToText(kind yaml.Kind) string {
|
||
|
switch kind {
|
||
|
case yaml.MappingNode:
|
||
|
return "map"
|
||
|
case yaml.SequenceNode:
|
||
|
return "seq"
|
||
|
case yaml.DocumentNode:
|
||
|
return "doc"
|
||
|
case yaml.ScalarNode:
|
||
|
return "scalar"
|
||
|
case yaml.AliasNode:
|
||
|
return "alias"
|
||
|
default:
|
||
|
return "unknown"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func getKindOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
|
||
|
log.Debugf("GetKindOperator")
|
||
|
|
||
|
var results = list.New()
|
||
|
|
||
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||
|
candidate := el.Value.(*CandidateNode)
|
||
|
node := &yaml.Node{Kind: yaml.ScalarNode, Value: kindToText(candidate.Node.Kind), Tag: "!!str"}
|
||
|
result := candidate.CreateReplacement(node)
|
||
|
results.PushBack(result)
|
||
|
}
|
||
|
|
||
|
return context.ChildContext(results), nil
|
||
|
}
|