just/src/command_ext.rs

34 lines
781 B
Rust
Raw Normal View History

2017-11-16 23:30:08 -08:00
use common::*;
pub trait CommandExt {
fn export_environment_variables<'a>(
&mut self,
scope: &Map<&'a str, String>,
dotenv: &Map<String, String>,
exports: &Set<&'a str>,
2017-11-17 17:28:06 -08:00
) -> RunResult<'a, ()>;
2017-11-16 23:30:08 -08:00
}
impl CommandExt for Command {
fn export_environment_variables<'a>(
&mut self,
scope: &Map<&'a str, String>,
dotenv: &Map<String, String>,
exports: &Set<&'a str>,
2017-11-17 17:28:06 -08:00
) -> RunResult<'a, ()> {
2018-03-05 13:21:35 -08:00
for (name, value) in dotenv {
self.env(name, value);
}
2017-11-16 23:30:08 -08:00
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),
2017-11-16 23:30:08 -08:00
});
}
}
Ok(())
}
}