Open ypicard opened 2 years ago
Similar issue to https://github.com/TomWright/dasel/issues/175.
I'll do some digging to see if I can find a decent solution to this
@TomWright I think this one is a bit different as it doesn't use the same data structure and therefore library. Xml seems to rely on mxj while yaml depends on gopkg.in/yaml.v2 v2.4.0
. The version v3 (gopkg.in/yaml.v3) support comments.
Thanks for the note on v3. It may be as easy as a version upgrade. I'll take a look
@olblak Where did you see that v3 supports comments?
That's a very good question. I couldn't find the changelog entry mentioning this. But I faced the same issue on https://github.com/updatecli and if I recall correctly switching to v3 solved it.
The original issue description reports comments being stripped out from a yaml. I would like to report that I observed the same behavior with a toml.
@tiogate I'm also interested in keeping the original comments in a toml config file. Did you find a solution for that ?
It seems that keeping comments is not supported by go-toml library at the moment (or the near future). See also https://github.com/pelletier/go-toml/issues/457
@TomWright did you take a look at an upgrade to yaml.v3
, and whether this preserves comments?
I definitely see comment-related fields in the Node
struct: https://pkg.go.dev/gopkg.in/yaml.v3#Node
@tiogate I'm also interested in keeping the original comments in a toml config file. Did you find a solution for that ?
@r10r Unfortunately I did not find a reasonable solution. In my case I only needed to modify one value in a TOML, so I did that with a hacky sed command. I also needed to make more complex modifications to JSON and YAML files though, and for that I used jq and yq.
Sorry I haven't looked yet - I've been pretty busy lately and haven't been able to find the time to support this as much as I'd like. I haven't forgotten though
I have an example where comments are not preserved with toml
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "settlement_layer" -v "dymension"
Discussion? Don't really know if I should file this as a feature request or a bug, let me know.
Describe the bug When updating files with the
dasel put
command, if comments are in the original file, they get stripped out from the output file. I would like to be able to keep them if I want to - or by default.To Reproduce Edit a
yaml
file containing comments with thedasel put
command. Output does not have comments anymore.example.yaml
:dasel put string -f example.yaml .version 0.2.0
Expected output: