mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Merge branch 'master' into new-merge2
This commit is contained in:
@@ -58,6 +58,21 @@ type jsonEncoder struct {
|
||||
encoder *json.Encoder
|
||||
}
|
||||
|
||||
func mapKeysToStrings(node *yaml.Node) {
|
||||
|
||||
if node.Kind == yaml.MappingNode {
|
||||
for index, child := range node.Content {
|
||||
if index % 2 == 0 { // its a map key
|
||||
child.Tag = "!!str"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, child := range node.Content {
|
||||
mapKeysToStrings(child)
|
||||
}
|
||||
}
|
||||
|
||||
func NewJsonEncoder(destination io.Writer, prettyPrint bool, indent int) Encoder {
|
||||
var encoder = json.NewEncoder(destination)
|
||||
var indentString = ""
|
||||
@@ -73,6 +88,8 @@ func NewJsonEncoder(destination io.Writer, prettyPrint bool, indent int) Encoder
|
||||
|
||||
func (je *jsonEncoder) Encode(node *yaml.Node) error {
|
||||
var dataBucket interface{}
|
||||
// firstly, convert all map keys to strings
|
||||
mapKeysToStrings(node)
|
||||
errorDecoding := node.Decode(&dataBucket)
|
||||
if errorDecoding != nil {
|
||||
return errorDecoding
|
||||
|
||||
@@ -29,9 +29,11 @@ func UpdateNavigationStrategy(updateCommand UpdateCommand, autoCreate bool) Navi
|
||||
}
|
||||
node.Anchor = changesToApply.Anchor
|
||||
node.Alias = changesToApply.Alias
|
||||
node.HeadComment = changesToApply.HeadComment
|
||||
node.LineComment = changesToApply.LineComment
|
||||
node.FootComment = changesToApply.FootComment
|
||||
if !updateCommand.DontUpdateComments {
|
||||
node.HeadComment = changesToApply.HeadComment
|
||||
node.LineComment = changesToApply.LineComment
|
||||
node.FootComment = changesToApply.FootComment
|
||||
}
|
||||
} else {
|
||||
log.Debug("skipping update as node already has value %v and overwriteFlag is ", node.Value, updateCommand.Overwrite)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user