just/src/load_dotenv.rs

26 lines
749 B
Rust
Raw Normal View History

use crate::common::*;
2018-03-05 13:21:35 -08:00
pub(crate) fn load_dotenv() -> RunResult<'static, BTreeMap<String, String>> {
// `dotenv::dotenv_iter` should eventually be un-deprecated, see:
// https://github.com/dotenv-rs/dotenv/issues/13
#![allow(deprecated)]
2018-03-05 13:21:35 -08:00
match dotenv::dotenv_iter() {
Ok(iter) => {
let mut dotenv = BTreeMap::new();
for result in iter {
let (key, value) = result.map_err(|dotenv_error| RuntimeError::Dotenv { dotenv_error })?;
if env::var_os(&key).is_none() {
dotenv.insert(key, value);
}
}
Ok(dotenv)
},
Err(dotenv_error) =>
if dotenv_error.not_found() {
Ok(BTreeMap::new())
} else {
Err(RuntimeError::Dotenv { dotenv_error })
},
2018-03-05 13:21:35 -08:00
}
}