-
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
EnvLoader::new().load()?
should not fail even if .env
file does not present.
#134
Comments
This has always been the default behaviour of dotenv/dotenvy. v0.15 or earlier fn main() {
dotenvy::dotenv().unwrap();
}
The new |
I wrote the code below, but there was no option to make the .env file optional. use dotenvy::{EnvLoader, EnvSequence};
fn main() {
EnvLoader::new().sequence(EnvSequence::EnvOnly).load().unwrap(); // Not panics
EnvLoader::new().sequence(EnvSequence::EnvThenInput).load().unwrap(); // Panics
EnvLoader::new().sequence(EnvSequence::InputThenEnv).load().unwrap(); // Panics
EnvLoader::new().sequence(EnvSequence::InputOnly).load().unwrap(); // Panics
println!("Hello, world!");
} This seems unintuitive from the user’s perspective. The dotenvy-macros crate has an option called "required" that makes the .env file optional. What do you think about adding a "required" option to dotenvy as well? // sample usage
let env = EnvLoader::new().required(false).load()?; References |
loader.required(false).existing_env(true).override(false) Having the configuration as a type is nice. It allows for this --> dev/prod example The config syntax of Thoughts? |
Cool. It seems like this would allow for all possible cases to be expressed, and it would greatly increase user flexibility as well.
It sounds good, but the types of values that can be passed as parameters within an attribute are extremely limited, so I’m not sure if it’s feasible to implement. If it’s possible, it would indeed be great. |
Reference: allan2/dotenvy#134 (comment)
It should proceed and silently defaults to
std::env::vars
, so that users can use dotenvy without.env
file. Almost all dotenv implementations in various programming languages function normally even without a .env file.The text was updated successfully, but these errors were encountered: