mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-08 06:45:38 +00:00
Return debug statements
This commit is contained in:
parent
37fd85768e
commit
f3d302b390
@ -17,19 +17,32 @@ func (o *CandidateNode) goccyDecodeIntoChild(childNode ast.Node, cm yaml.Comment
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error {
|
func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error {
|
||||||
|
log.Debugf("UnmarshalYAML %v", node)
|
||||||
|
log.Debugf("UnmarshalYAML %v", node.Type().String())
|
||||||
|
log.Debugf("UnmarshalYAML Node Value: %v", node.String())
|
||||||
|
log.Debugf("UnmarshalYAML Node GetComment: %v", node.GetComment())
|
||||||
|
|
||||||
if node.GetComment() != nil {
|
if node.GetComment() != nil {
|
||||||
commentMapComments := cm[node.GetPath()]
|
commentMapComments := cm[node.GetPath()]
|
||||||
for _, comment := range node.GetComment().Comments {
|
for _, comment := range node.GetComment().Comments {
|
||||||
|
// need to use the comment map to find the position :/
|
||||||
|
log.Debugf("%v has a comment of [%v]", node.GetPath(), comment.Token.Value)
|
||||||
for _, commentMapComment := range commentMapComments {
|
for _, commentMapComment := range commentMapComments {
|
||||||
commentMapValue := strings.Join(commentMapComment.Texts, "\n")
|
commentMapValue := strings.Join(commentMapComment.Texts, "\n")
|
||||||
if commentMapValue == comment.Token.Value {
|
if commentMapValue == comment.Token.Value {
|
||||||
|
log.Debug("found a matching entry in comment map")
|
||||||
|
// we found the comment in the comment map,
|
||||||
|
// now we can process the position
|
||||||
switch commentMapComment.Position {
|
switch commentMapComment.Position {
|
||||||
case yaml.CommentHeadPosition:
|
case yaml.CommentHeadPosition:
|
||||||
o.HeadComment = comment.String()
|
o.HeadComment = comment.String()
|
||||||
|
log.Debug("its a head comment %v", comment.String())
|
||||||
case yaml.CommentLinePosition:
|
case yaml.CommentLinePosition:
|
||||||
o.LineComment = comment.String()
|
o.LineComment = comment.String()
|
||||||
|
log.Debug("its a line comment %v", comment.String())
|
||||||
case yaml.CommentFootPosition:
|
case yaml.CommentFootPosition:
|
||||||
o.FootComment = comment.String()
|
o.FootComment = comment.String()
|
||||||
|
log.Debug("its a foot comment %v", comment.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,6 +65,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!bool"
|
o.Tag = "!!bool"
|
||||||
case ast.NullType:
|
case ast.NullType:
|
||||||
|
log.Debugf("its a null type with value %v", node.GetToken().Value)
|
||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!null"
|
o.Tag = "!!null"
|
||||||
o.Value = node.GetToken().Value
|
o.Value = node.GetToken().Value
|
||||||
@ -68,24 +82,30 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
o.Style = DoubleQuotedStyle
|
o.Style = DoubleQuotedStyle
|
||||||
}
|
}
|
||||||
o.Value = node.(*ast.StringNode).Value
|
o.Value = node.(*ast.StringNode).Value
|
||||||
|
log.Debugf("string value %v", node.(*ast.StringNode).Value)
|
||||||
case ast.LiteralType:
|
case ast.LiteralType:
|
||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!str"
|
o.Tag = "!!str"
|
||||||
o.Style = LiteralStyle
|
o.Style = LiteralStyle
|
||||||
astLiteral := node.(*ast.LiteralNode)
|
astLiteral := node.(*ast.LiteralNode)
|
||||||
|
log.Debugf("astLiteral.Start.Type %v", astLiteral.Start.Type)
|
||||||
if astLiteral.Start.Type == goccyToken.FoldedType {
|
if astLiteral.Start.Type == goccyToken.FoldedType {
|
||||||
|
log.Debugf("folded Type %v", astLiteral.Start.Type)
|
||||||
o.Style = FoldedStyle
|
o.Style = FoldedStyle
|
||||||
}
|
}
|
||||||
// Preserving the original multiline string value is important for fidelity.
|
log.Debug("start value: %v ", node.(*ast.LiteralNode).Start.Value)
|
||||||
// goccy/go-yaml provides this in astLiteral.Value.Value for literal and folded styles.
|
log.Debug("start value: %v ", node.(*ast.LiteralNode).Start.Type)
|
||||||
|
// TODO: here I could put the original value with line breaks
|
||||||
|
// to solve the multiline > problem
|
||||||
o.Value = astLiteral.Value.Value
|
o.Value = astLiteral.Value.Value
|
||||||
case ast.TagType:
|
case ast.TagType:
|
||||||
// Recursively unmarshal the tagged value, then apply the tag to the CandidateNode.
|
// Recursively unmarshal the tagged value, then apply the tag to the CandidateNode.
|
||||||
if err := o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm, anchorMap); err != nil {
|
if err := o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm, anchorMap); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
o.Tag = node.(*ast.TagNode).Start.Value // Tag value includes the '!' or '!!' prefix.
|
o.Tag = node.(*ast.TagNode).Start.Value
|
||||||
case ast.MappingType:
|
case ast.MappingType:
|
||||||
|
log.Debugf("UnmarshalYAML - a mapping node")
|
||||||
o.Kind = MappingNode
|
o.Kind = MappingNode
|
||||||
o.Tag = "!!map"
|
o.Tag = "!!map"
|
||||||
|
|
||||||
@ -100,9 +120,11 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if mappingNode.FootComment != nil {
|
if mappingNode.FootComment != nil {
|
||||||
|
log.Debugf("mapping node has a foot comment of: %v", mappingNode.FootComment)
|
||||||
o.FootComment = mappingNode.FootComment.String()
|
o.FootComment = mappingNode.FootComment.String()
|
||||||
}
|
}
|
||||||
case ast.MappingValueType:
|
case ast.MappingValueType:
|
||||||
|
log.Debugf("UnmarshalYAML - a mapping node")
|
||||||
o.Kind = MappingNode
|
o.Kind = MappingNode
|
||||||
o.Tag = "!!map"
|
o.Tag = "!!map"
|
||||||
mappingValueNode := node.(*ast.MappingValueNode)
|
mappingValueNode := node.(*ast.MappingValueNode)
|
||||||
@ -111,6 +133,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ast.SequenceType:
|
case ast.SequenceType:
|
||||||
|
log.Debugf("UnmarshalYAML - a sequence node")
|
||||||
o.Kind = SequenceNode
|
o.Kind = SequenceNode
|
||||||
o.Tag = "!!seq"
|
o.Tag = "!!seq"
|
||||||
sequenceNode := node.(*ast.SequenceNode)
|
sequenceNode := node.(*ast.SequenceNode)
|
||||||
@ -135,6 +158,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
o.Content[i] = valueNode
|
o.Content[i] = valueNode
|
||||||
}
|
}
|
||||||
case ast.AnchorType:
|
case ast.AnchorType:
|
||||||
|
log.Debugf("UnmarshalYAML - an anchor node")
|
||||||
anchorNode := node.(*ast.AnchorNode)
|
anchorNode := node.(*ast.AnchorNode)
|
||||||
err := o.UnmarshalGoccyYAML(anchorNode.Value, cm, anchorMap)
|
err := o.UnmarshalGoccyYAML(anchorNode.Value, cm, anchorMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,14 +168,16 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
|
|||||||
anchorMap[o.Anchor] = o
|
anchorMap[o.Anchor] = o
|
||||||
|
|
||||||
case ast.AliasType:
|
case ast.AliasType:
|
||||||
|
log.Debugf("UnmarshalYAML - an alias node")
|
||||||
aliasNode := node.(*ast.AliasNode)
|
aliasNode := node.(*ast.AliasNode)
|
||||||
o.Kind = AliasNode
|
o.Kind = AliasNode
|
||||||
o.Value = aliasNode.Value.String()
|
o.Value = aliasNode.Value.String()
|
||||||
o.Alias = anchorMap[o.Value]
|
o.Alias = anchorMap[o.Value]
|
||||||
|
|
||||||
case ast.MergeKeyType:
|
case ast.MergeKeyType:
|
||||||
|
log.Debugf("UnmarshalYAML - a merge key")
|
||||||
o.Kind = ScalarNode
|
o.Kind = ScalarNode
|
||||||
o.Tag = "!!merge"
|
o.Tag = "!!merge" // note - I should be able to get rid of this.
|
||||||
o.Value = "<<"
|
o.Value = "<<"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user