Loads the environment variables from the repository root .env files.
(environment: impl Into<Option<Environment>>)
| 46 | |
| 47 | /// Loads the environment variables from the repository root .env files. |
| 48 | pub fn load_env(environment: impl Into<Option<Environment>>) -> Vec<PathBuf> { |
| 49 | let environment = environment.into().unwrap_or(if cfg!(test) { |
| 50 | Environment::Test |
| 51 | } else if cfg!(debug_assertions) { |
| 52 | Environment::Development |
| 53 | } else { |
| 54 | Environment::Production |
| 55 | }); |
| 56 | |
| 57 | let environment_path = format!(".env.{environment}"); |
| 58 | let environment_path_local = format!(".env.{environment}.local"); |
| 59 | |
| 60 | [ |
| 61 | ".env.local", |
| 62 | &environment_path_local, |
| 63 | &environment_path, |
| 64 | ".env", |
| 65 | ] |
| 66 | .into_iter() |
| 67 | .filter_map(|path| { |
| 68 | dotenv_flow::from_filename( |
| 69 | Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../../..")).join(path), |
| 70 | ) |
| 71 | .ok() |
| 72 | }) |
| 73 | .collect() |
| 74 | } |