2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2018-03-05 13:21:35 -08:00
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn load_dotenv() -> RunResult<'static, BTreeMap<String, String>> {
|
2019-10-22 19:51:50 -07:00
|
|
|
// `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) => {
|
2020-07-16 21:37:33 -07:00
|
|
|
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)
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
|
|
|
Err(dotenv_error) =>
|
2018-12-08 14:29:41 -08:00
|
|
|
if dotenv_error.not_found() {
|
2019-04-11 15:23:14 -07:00
|
|
|
Ok(BTreeMap::new())
|
2018-12-08 14:29:41 -08:00
|
|
|
} else {
|
|
|
|
Err(RuntimeError::Dotenv { dotenv_error })
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2018-03-05 13:21:35 -08:00
|
|
|
}
|
|
|
|
}
|