just/src/command_ext.rs
Casey Rodarmor 3a287b864a
Housekeeping (#394)
- Upgrade to rust 2018
- Update dependencies
- Use BTree{Map,Set} instead of Map and Set
2019-04-11 15:23:14 -07:00

34 lines
818 B
Rust

use crate::common::*;
pub trait CommandExt {
fn export_environment_variables<'a>(
&mut self,
scope: &BTreeMap<&'a str, String>,
dotenv: &BTreeMap<String, String>,
exports: &BTreeSet<&'a str>,
) -> RunResult<'a, ()>;
}
impl CommandExt for Command {
fn export_environment_variables<'a>(
&mut self,
scope: &BTreeMap<&'a str, String>,
dotenv: &BTreeMap<String, String>,
exports: &BTreeSet<&'a str>,
) -> RunResult<'a, ()> {
for (name, value) in dotenv {
self.env(name, value);
}
for name in exports {
if let Some(value) = scope.get(name) {
self.env(name, value);
} else {
return Err(RuntimeError::Internal {
message: format!("scope does not contain exported variable `{}`", name),
});
}
}
Ok(())
}
}