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

for V2: add support for comments #1966

Open
1 task done
drsybren opened this issue Dec 16, 2024 · 0 comments
Open
1 task done

for V2: add support for comments #1966

drsybren opened this issue Dec 16, 2024 · 0 comments
Labels
kind/enhancement New feature or request

Comments

@drsybren
Copy link

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

It would be fantastic if Viper would support adding comments to configuration files and individual fields.

Currently my application writes YAML config file the following header:

# Configuration file for ${APPLICATION NAME}.
# For an explanation of the fields, refer to {application}-example.yaml
#
# NOTE: this file will be overwritten by ${APPLICATION NAME}'s web-based configuration system.
#
# This file was written on ${TIMESTAMP} by ${APPLICATION NAME}-${VERSION}

Having Viper produce such a header (on file types where comments are supported, of course) would be fantastic. Also in this particular header you can see that there's an example file with documentation in the comments. Having such documention comments produced by Viper would be amazing, as then the file itself could be written like:

# ${APPLICATION} listens to incoming connections from workers on this address.
listen: ':8080'

Proposed Solution

An API like this could work:

v.SetDocumentation("Configuration file for ${APPLICATION NAME}....")

v.SetDefault("listen", ":8080")
v.SetFieldDocumentation("listen", ${APPLICATION} listens to incoming connections from workers on this address.")

Alternatives Considered

The obvious alternative is to simply not have support for comments, as we have now.

Additional Information

An open question would be what to do with existing comments in the file. Would these be remembered when rewriting? Or would rewriting the config file always write the set-in-the-code documentation strings? I think the latter would be the easiest to implement, and it also allows updating that documentation in the config file when the application is updated.

@drsybren drsybren added the kind/enhancement New feature or request label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant