use std::collections::BTreeMap;
#[cfg(unix)]
const BASE_NAMES: &[&str] = &["PATH", "HOME", "LANG", "LC_ALL", "LC_CTYPE", "TZ"];
#[cfg(windows)]
const BASE_NAMES: &[&str] = &[
"PATH",
"SystemRoot",
"SystemDrive",
"ComSpec",
"PATHEXT",
"TEMP",
"TMP",
"USERPROFILE",
];
pub fn base_environment_names() -> &'static [&'static str] {
BASE_NAMES
}
pub fn child_environment<F>(allowlist: &[String], mut read: F) -> BTreeMap<String, String>
where
F: FnMut(&str) -> Option<String>,
{
let mut environment: BTreeMap<String, String> = BASE_NAMES
.iter()
.copied()
.map(str::to_owned)
.chain(allowlist.iter().cloned())
.filter_map(|name| read(&name).map(|value| (name, value)))
.collect();
environment.insert(super::IN_HOOK_ENV.to_owned(), "1".into());
environment
}
pub fn ambient(name: &str) -> Option<String> {
std::env::var(name).ok()
}
#[cfg(test)]
#[path = "environment_tests.rs"]
mod tests;