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

Allow changing the default value of the commented tag #423

Closed
fho opened this issue Jul 9, 2020 · 4 comments
Closed

Allow changing the default value of the commented tag #423

fho opened this issue Jul 9, 2020 · 4 comments
Labels
feature Issue asking for a new feature in go-toml.

Comments

@fho
Copy link

fho commented Jul 9, 2020

Is your feature request related to a problem? Please describe.

I would like to use the same toml struct to marshal a struct with concrete values to a file and to generate example configuration file.
In the example configuration file, all lines should be commented.
Currently it's only possible to change the commented option per field tag.
I can only comment or uncomment them but not have both variants when marshalling the same struct.

Describe the solution you'd like

Add an encoder option to change the default commented setting for fields.
This way it would be possible to omit the commented tag and set the default to true when marshaling the struct as an example config.

Describe alternatives you've considered

  • Instead of having an option to set the default, have an option to enforce/overwrite the commented tag for all fields in the encoder
  • Add the the tag commented = true to all my fields, when I'm not marshalling the struct into an example config, call e.SetTagCommented("nonexistingtag)` to ignore the tag setting and have everything uncommented
@fho fho changed the title Allow changing the default commented value Allow changing the default value of the commented tag Jul 9, 2020
@pelletier pelletier added the feature Issue asking for a new feature in go-toml. label Aug 1, 2020
@pelletier
Copy link
Owner

Thank you for the suggestion! I think that should definitely be part of the API.

@pelletier
Copy link
Owner

Closing this issue, as go-toml v2.0.0 has been released, and commented tags are not supported anymore. 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!

@lordvidex
Copy link

@pelletier when upgrading to go-toml v2, how can one still replicate the commented tag feature, such that some toml field is commented out after marshalling.

@pelletier
Copy link
Owner

It's not possible at the moment. One option would be to perform some post-processing on the output if you know how fields would look like. Or you help out on the marshaling of the new AST struct (#822).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue asking for a new feature in go-toml.
Projects
None yet
Development

No branches or pull requests

3 participants