yq/pkg/yqlib/value_parser.go

39 lines
973 B
Go
Raw Normal View History

package yqlib
import (
2019-12-16 05:46:20 +00:00
yaml "gopkg.in/yaml.v3"
)
type ValueParser interface {
Parse(argument string, customTag string, customStyle string) *yaml.Node
}
2019-12-16 05:46:20 +00:00
type valueParser struct {
}
2020-01-08 21:17:56 +00:00
func NewValueParser() ValueParser {
return &valueParser{}
}
func (v *valueParser) Parse(argument string, customTag string, customStyle string) *yaml.Node {
var style yaml.Style
if customStyle == "tagged" {
style = yaml.TaggedStyle
} else if customStyle == "double" {
style = yaml.DoubleQuotedStyle
} else if customStyle == "single" {
style = yaml.SingleQuotedStyle
} else if customStyle == "literal" {
style = yaml.LiteralStyle
} else if customStyle == "folded" {
style = yaml.FoldedStyle
} else if customStyle != "" {
log.Error("Unknown style %v, ignoring", customStyle)
}
2020-01-19 21:42:08 +00:00
if argument == "[]" {
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode, Style: style}
}
return &yaml.Node{Value: argument, Tag: customTag, Kind: yaml.ScalarNode, Style: style}
}