2019-12-03 04:50:32 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
2019-12-16 05:46:20 +00:00
|
|
|
yaml "gopkg.in/yaml.v3"
|
2019-12-03 04:50:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ValueParser interface {
|
2020-06-11 03:57:13 +00:00
|
|
|
Parse(argument string, customTag string, customStyle string, anchorName string, createAlias bool) *yaml.Node
|
2019-12-03 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 05:46:20 +00:00
|
|
|
type valueParser struct {
|
|
|
|
}
|
2019-12-03 04:50:32 +00:00
|
|
|
|
2020-01-08 21:17:56 +00:00
|
|
|
func NewValueParser() ValueParser {
|
|
|
|
return &valueParser{}
|
2019-12-03 04:50:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 03:57:13 +00:00
|
|
|
func (v *valueParser) Parse(argument string, customTag string, customStyle string, anchorName string, createAlias bool) *yaml.Node {
|
2020-04-17 01:03:43 +00:00
|
|
|
var style yaml.Style
|
|
|
|
if customStyle == "tagged" {
|
|
|
|
style = yaml.TaggedStyle
|
2020-04-17 01:24:45 +00:00
|
|
|
} else if customStyle == "double" {
|
2020-04-17 01:03:43 +00:00
|
|
|
style = yaml.DoubleQuotedStyle
|
2020-04-17 01:24:45 +00:00
|
|
|
} else if customStyle == "single" {
|
2020-04-17 01:03:43 +00:00
|
|
|
style = yaml.SingleQuotedStyle
|
|
|
|
} else if customStyle == "literal" {
|
|
|
|
style = yaml.LiteralStyle
|
|
|
|
} else if customStyle == "folded" {
|
|
|
|
style = yaml.FoldedStyle
|
2020-06-10 23:58:10 +00:00
|
|
|
} else if customStyle == "flow" {
|
|
|
|
style = yaml.FlowStyle
|
2020-04-17 01:24:45 +00:00
|
|
|
} else if customStyle != "" {
|
|
|
|
log.Error("Unknown style %v, ignoring", customStyle)
|
2020-04-17 01:03:43 +00:00
|
|
|
}
|
2020-01-19 21:42:08 +00:00
|
|
|
if argument == "[]" {
|
2020-04-17 01:03:43 +00:00
|
|
|
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode, Style: style}
|
2019-12-03 04:50:32 +00:00
|
|
|
}
|
2020-06-11 03:57:13 +00:00
|
|
|
|
|
|
|
kind := yaml.ScalarNode
|
|
|
|
|
|
|
|
if createAlias {
|
|
|
|
kind = yaml.AliasNode
|
|
|
|
}
|
|
|
|
|
|
|
|
return &yaml.Node{Value: argument, Tag: customTag, Kind: kind, Style: style, Anchor: anchorName}
|
2019-12-03 04:50:32 +00:00
|
|
|
}
|