-
Notifications
You must be signed in to change notification settings - Fork 47
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
v0.16 new API #123
Merged
v0.16 new API #123
Conversation
This file contains 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
`set::env_set_var` is unsafe in the 2024 edition. All functions calling it are marked as unsafe.
- dotenv moved to dotenvy folder - dotenvy-macros crate created for runtime macros - temporary 2024 edition to check for unsafe `set_var` usage - new API with `EnvLoader` builder, `load`, and `load_and_modify` - `load` attribute macro that is thread-safe and async-compatible - many examples added - some irrelevant tests removed
This naming better reflects the fact that we are configuring a loader with an optional path, with deferred I/O.
This removes the `EnvVar` variant which wraps `VarError`. The internals of `VarError` are now variants in `Error`. This makes it more ergonomic for users who are propogating errors to know which varaible is truly missing.
This reintroduces `var` as a copy of `std::env::var` with more info. The signature is different because in this crate, we only handle valid UTF-8. Calling `var` now gives the key name in the error.
This change `EnvMap` to a newtype with a `var` function that returns `Result`. This mirrors the behaviour of `dotenvy::var`.
This makes the CLI feature aligned with the attribute macro. The optional example is also updated to be similar to the CLI. `Path::exists` is no longer used because of a potential race condition.
Error messages are also adjusted.
Would adding a |
No, I will revert the edition. More tests and docs still need to be added. |
This creates an internal `ParseBufError` to handle line parsing errors without the path context. Loading a file reports the file path error if an attempt was made to read from it and it is not found.
`EnvLoader::path` is a setter that can be used to specify the path. If `with_reader` is used, the path can be specified for error context. If both reader and path are present, load will use the reader as input.
Now that we only use paths and there is also reader input, we don't need to test with temp file creating and deleting.
The tests are also rewritten for clarity.
Tests are also moved from separate files to the `EnvLoader` module.
The integration tests are no longer being used. Testing is done at lower levels and will be stored as modules.
Unit tests run in parallel and may clobber each other. temp-env is now a dev dependency to ensure that unit tests run in isolated enviornments. Some tests are added for `load` and `load_and_modify`.
This is to build with clap_builder v4.5.17, which requires 17.4.0. 1.74.0 came out November 2023, so this is less than one year ago.
`cmd.exec` was accessible to the Windows code path, while also being unreachable do to `exit(1)`.
We consistenly use "env file" across the repo now.
`override` argument named to `override_` because it is a keyword.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a breaking fast-forward PR.
std::env::set_var
is marked unsafe in the Rust 2024 edition.set_var
is used in majority of functions in v0.15.This PR introduces a non-modifying API for loading of environment variables. Modifying of the environment is also supported with improved ergonomics limiting the use of
unsafe
.EnvLoader
with_path
andwith_reader
entry points with deferred IOEnvSequence
load
load_and_modify
EnvMap
is aHashMap
newtype withEnvMap::var
load
attribute macroError
type contains the variable nameVarError
is now flattened toError
variants containing the called variable namefrom_filename
deprecated to prevent directory traversal attackfind
example added to replicate the old behaviourMore docs and tests have to be added. Feedback is welcome.
Further reading:
set_var
docsstd::env::VarError::NotPresent
Resolves #14, resolves #25, resolves #39, resolves #68, resolves #105, resolves #106, resolves #48
Progresses #112