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

Is there a good way to modify a toml file? #457

Closed
mq0427 opened this issue Nov 25, 2020 · 6 comments
Closed

Is there a good way to modify a toml file? #457

mq0427 opened this issue Nov 25, 2020 · 6 comments
Labels
document Issues related to Document Editing question Question from a go-toml user.

Comments

@mq0427
Copy link

mq0427 commented Nov 25, 2020

Is there a good way to modify a toml file? I just have to modify the value of some keys. And I would like to just keep all the other things unchanged, such as the order of the keys and the comments. It seems it can be achieved by LoadFile and then set the new value and call WriteTo to overwrite the toml file, but the original layout like the order of the keys and the comments will be lost.

@pelletier
Copy link
Owner

Unfortunately not yet. As far as I know the best you can do today is to decide that the file should always be "linted" and have go-toml sort it on write.

Edit-in-place is definitely something I would love to see as well. Most of the pieces are already there: LoadFile keeps track of positions of what it read, and Encoder has some logic to change what order things should be emitted.

@pelletier pelletier added the question Question from a go-toml user. label Nov 25, 2020
@pelletier pelletier added this to the Document support milestone Nov 25, 2020
@mq0427
Copy link
Author

mq0427 commented Nov 26, 2020

@pelletier, thanks for reply. Any plans to support "Edit-in-place"?

@pelletier
Copy link
Owner

Not personally -- my free time has been close to non-existent lately, as the delay in this reply shows. If anyone wants to tackle this I'll happily review pull requests.

@prakashmirji
Copy link

I am also looking for this feature. We want to edit some keys or add new keys through programmatically.

@pelletier
Copy link
Owner

Thanks for your interest in go-toml! I'm currently working (albeit slowly) on defining the document editing interface for go-toml v2. It should address this issue.

If you have ideas or examples of what you'd like it to look like I'd love to see them!

@pelletier pelletier added the document Issues related to Document Editing label Oct 23, 2021
@pelletier pelletier removed this from the v2.0.0-beta.4 milestone Oct 23, 2021
@pelletier
Copy link
Owner

Closing this issue, as go-toml v2.0.0 has been released, and document manipulation is out of scope for v2. As go-toml v1 will not be receiving any updates, please look into upgrading to the new version. If you believe this is a mistake please reach out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document Issues related to Document Editing question Question from a go-toml user.
Projects
None yet
Development

No branches or pull requests

3 participants