Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve comments when editing files #178

Open
ypicard opened this issue Nov 1, 2021 · 11 comments
Open

Preserve comments when editing files #178

ypicard opened this issue Nov 1, 2021 · 11 comments
Labels
bug Something isn't working

Comments

@ypicard
Copy link

ypicard commented Nov 1, 2021

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 the dasel put command. Output does not have comments anymore.

  • create an original yaml file named example.yaml:
apiVersion: v2
type: application
# Comment 1
version: 0.1.0
# Comment 2
appVersion: 0.1.0
  • execute: dasel put string -f example.yaml .version 0.2.0
  • Output looks like:
apiVersion: v2
appVersion: 0.1.0
type: application
version: 0.2.0

Expected output:

apiVersion: v2
type: application
# Comment 1
version: 0.2.0
# Comment 2
appVersion: 0.1.0
@ypicard ypicard added the bug Something isn't working label Nov 1, 2021
@TomWright
Copy link
Owner

Similar issue to #175.

I'll do some digging to see if I can find a decent solution to this

@olblak
Copy link

olblak commented Nov 7, 2021

@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.

@TomWright
Copy link
Owner

Thanks for the note on v3. It may be as easy as a version upgrade. I'll take a look

@TomWright
Copy link
Owner

@olblak Where did you see that v3 supports comments?

@olblak
Copy link

olblak commented Nov 12, 2021

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.

@tiogate
Copy link

tiogate commented Dec 9, 2021

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.

@r10r
Copy link

r10r commented Jun 13, 2022

@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 pelletier/go-toml#457

@flokli
Copy link

flokli commented Jun 27, 2022

@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
Copy link

tiogate commented Jun 28, 2022

@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.

@TomWright
Copy link
Owner

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

@danwt
Copy link

danwt commented Apr 18, 2024

I have an example where comments are not preserved with toml

dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "settlement_layer" -v "dymension"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants