-
Notifications
You must be signed in to change notification settings - Fork 253
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
Open
chickencoding123
wants to merge
1
commit into
rust-cli:main
Choose a base branch
from
chickencoding123:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use std::error::Error; | ||
| use std::io::Cursor; | ||
|
|
||
| use crate::map::Map; | ||
| use crate::value::{Value, ValueKind}; | ||
|
|
||
| pub(crate) fn parse( | ||
| uri: Option<&String>, | ||
| text: &str, | ||
| ) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> { | ||
| let mut map: Map<String, Value> = Map::new(); | ||
| let str_iter = dotenvy::Iter::new(Cursor::new(text)); | ||
| for item in str_iter { | ||
| let (key, value) = item?; | ||
| map.insert(key, Value::new(uri, ValueKind::String(value))); | ||
| } | ||
|
|
||
| Ok(map) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| foobar="I am FOOBAR envfile" | ||
| foo="I am foo envfile" | ||
| bar="I am BAR envfile" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| foobar="I am FOOBAR envfile local" | ||
| foo="I am foo envfile local" | ||
| bar="I am BAR envfile local" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 withEnvironmentthat we'd want to make this functionality on that.Uh oh!
There was an error while loading. Please reload this page.
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. Alsodotenvydependency will take care of the overlap, if any. However I ensured OS env take precedence as per existing 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.
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
Both of these characteristics are shared with
Environmentwhich 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.
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 updated to strike a balance between dotenv ambitions and preferences of this repository.
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'm not aware of any dotenv "ambitions" that come in conflict with "preferences of this repository". Also, for any "preferences" I'm giving, they are about fully supporting dotenv rather than doing it party way.