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

Way to keep commented out lines after unmarshalling #903

Closed
fmuyassarov opened this issue Sep 26, 2023 · 2 comments
Closed

Way to keep commented out lines after unmarshalling #903

fmuyassarov opened this issue Sep 26, 2023 · 2 comments
Labels
question Question from a go-toml user.

Comments

@fmuyassarov
Copy link

Hi. Does go-toml v2 support keeping the commented out lines of a TOML file when unmarshaling and marshaling?
I'm manipulating a TOML based configuration file and eventually, commented out lines are getting clean up. It would be nice to have an option to keep them as it is.

Example

# The CRI-O configuration file specifies all of the available configuration
# options and command-line flags for the crio(8) OCI Kubernetes Container Runtime
# daemon, but in a TOML format that can be more easily modified and versioned.
#
# Please refer to crio.conf(5) for details of all configuration options.
[crio]
@pelletier
Copy link
Owner

The answer to this question depends largely on what types are involved and the kind of operations you want to make.

go-toml has support for commented struct fields (example).

You can also use the unstable.AST to parse the document, keeping comments. However there is no easy way to write it back out at the moment. You should be able to generate your own struct types dynamically to achieve this. Check out #822 about this topic – pull request to add encoder methods to the unstable.AST would be welcomed!

@pelletier pelletier added the question Question from a go-toml user. label Oct 23, 2023
@pelletier
Copy link
Owner

Closing this, feel free to open a discussion if there is more to discuss about this subject!

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

No branches or pull requests

2 participants