robin/utils/env_file.rs
1use std::path::Path;
2
3/// Loads a `.env` file living next to the given config file into the process
4/// environment, so that both robin's own `${VAR:-default}` substitution and the
5/// shell see the variables. Existing environment variables always win (standard
6/// dotenv precedence), and a missing file is not an error.
7///
8/// Set `ROBIN_NO_DOTENV` to skip loading entirely.
9pub fn load_env_file(config_path: &Path) {
10 if std::env::var_os("ROBIN_NO_DOTENV").is_some() {
11 return;
12 }
13
14 let dir = config_path.parent().unwrap_or_else(|| Path::new("."));
15 let env_path = dir.join(".env");
16 if env_path.is_file() {
17 // Best-effort: never let a malformed .env break a real command.
18 let _ = dotenvy::from_path(&env_path);
19 }
20}