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
add support for writing arbitrary dotfiles #932
Comments
Thanks @greg-szabo. Friendly observation that the fix in #934 is still probably sub-optimal for this case since
feels a bit kludgy to be. Another possibility would be to support dotfiles with any extension, eg.:
|
Ah, interesting, thanks for pointing it out. #934 fixes the original example in this issue, where you have a random filename with a random extension and you want to force it to be a yaml configuration. I guess it needs more clarification what exactly you want to achieve. As far as I understand I don't know if Viper supports "files that start with a dot" somehow differently. The To summarize: currently, you have to name your file explicitly |
My observation is just that, arbitrary dotfiles are quite common as config files, of any type (yaml, env, etc.). After #934, it will be possible to support those files with something that feels a bit hacky:
which IIUC only works correctly if it's a dotenv file (not eg. yaml). A future refactor might just require |
Nope, that's not the case (I mean the hacky solution is not the case). I think you're misusing SetConfigType there. The only valid SetConfigType strings are defined in SupportedExts mentioned above. It seems that it accepted the string, but when you try to save the file, it will complain that it's an Currently, if your file name is After implementing #934, this will be a valid way to save the config file:
Essentially, #934 allows you to write arbitrary dotfiles, as you requested in the issue. The only thing you need to change in the above code is the file name. The ConfigType will always be dotenv, yaml, json or whatever type the file actually contains. It will not be the extension of your file. This is literally the "another possibility" you mentioned in your comment. It's already implemented, only it's not called "dotfile", it's called "dotenv". And it's missing the change in #934 to actually work. I have different reasons to request #934. If you want to push a different solution, that's fair. I was just trying to help. |
Support for extensionless and dotenv files has been added, and for reading any file, but commonly used arbitrary dotfiles are not supported at the write stage:
The text was updated successfully, but these errors were encountered: