You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's entirely possible that I'm using this incorrectly, but it seems that yaml.CommentToMap(cm) only retrieves comments if they're on the first key for each map. Should I be decoding to something other than a MapSlice?
package main
import (
"bytes""fmt""io""github.com/goccy/go-yaml"
)
varcontents= []byte(`top: # This comment is captured first: true # But not this one second: # But this one is first: true # But not this one second: true # Neither this third: true`)
funcmain() {
cm:= yaml.CommentMap{}
dec:=yaml.NewDecoder(bytes.NewReader(contents), yaml.UseOrderedMap(), yaml.CommentToMap(cm))
for {
varmslice yaml.MapSliceerr:=dec.Decode(&mslice)
iferr==io.EOF {
break
}
iferr!=nil {
panic(err)
}
}
for_, comment:=rangecm {
fmt.Println(comment.Texts)
}
}
// ➜ go run main.go// [ But this one is]// [ This comment is captured]
I need to edit some values in hundreds of files, preserving as much as I can. This is blocking that. 😅
The text was updated successfully, but these errors were encountered:
It's entirely possible that I'm using this incorrectly, but it seems that
yaml.CommentToMap(cm)
only retrieves comments if they're on the first key for each map. Should I be decoding to something other than aMapSlice
?I need to edit some values in hundreds of files, preserving as much as I can. This is blocking that. 😅
The text was updated successfully, but these errors were encountered: