-
Couldn't load subscription status.
- Fork 252
feat(dotenv): Adding support for dotenv files #710
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
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 18750157020Details
💛 - Coveralls |
|
|
||
| /// Dotenv (parsed with `dotenvy`) | ||
| #[cfg(feature = "dotenv")] | ||
| Dotenv, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work as another FileFormat / Source? I suspect there is a lot of design overlap with Environment that we'd want to make this functionality on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another FileFormat. You can see the usage from the tests (added snippet for ref. here). It is similar to existing file formats. Also dotenvy dependency will take care of the overlap, if any. However I ensured OS env take precedence as per existing file formats.
let s = Config::builder()
.add_source(config::File::from_str(
r#"
FOO=bar
BAZ=qux
"#,
config::FileFormat::Dotenv,
))
.build()
.unwrap();There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI resolving conversations that aren't ready for it can make PR reviews more difficult on maintainers. You should be pretty confident that you understood the concern and responded to it as the maintainer expected to resolve it. That was not the case here.
Some traits of dotenv are
- Stringly typed (so is ini)
- Unstructured
Both of these characteristics are shared with Environment which has a lot of functionality for solving these problems. In fact, this is another form of environment variables! The only difference is it also shares some of the file loading characteristics of file formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've raised this (and other questions) at #16 (comment) as I prefer to work out high level designs in Issues rather than PRs.
|
Feel free to modify your commits for how they should be merged |
bab1683 to
1f7f117
Compare
| for item in from_read_iter(cursor) { | ||
| let (key, mut value) = item?; | ||
|
|
||
| let os_env_vars = std::env::vars_os(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be doing manual layering, that is what the ConfigBuilder is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dotenvy overrides OS var which is inconsistent with existing FileFormat in this crate. Manual layering is appealing here because file formats sit below ConfigBuilder in the hierarchy. Coupling a ConfigBuilder inside a file format will lead to difficult refactoring in the future.
I think for the purposes of this specific file format, simple env override should suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual layering is appealing here because file formats sit below ConfigBuilder in the hierarchy. Coupling a ConfigBuilder inside a file format will lead to difficult refactoring in the future.
Environment and each File are manually added as sources and the user has control over the precedence order. However we support DotEnv, it will be similar, so we don't need to do this here. If we did,. it would belong in Environment which is what is handling the OS vars.
This adds support for dotenv file format. It is accomplished by using dotenvy crate. There's an open issue asking for this feature here #16.