just/src/command_ext.rs

32 lines
708 B
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
pub(crate) trait CommandExt {
fn export(&mut self, dotenv: &BTreeMap<String, String>, scope: &Scope);
fn export_scope(&mut self, scope: &Scope);
2017-11-16 23:30:08 -08:00
}
impl CommandExt for Command {
fn export(&mut self, dotenv: &BTreeMap<String, String>, scope: &Scope) {
2018-03-05 13:21:35 -08:00
for (name, value) in dotenv {
self.env(name, value);
}
if let Some(parent) = scope.parent() {
self.export_scope(parent);
2017-11-16 23:30:08 -08:00
}
}
fn export_scope(&mut self, scope: &Scope) {
if let Some(parent) = scope.parent() {
self.export_scope(parent);
}
for binding in scope.bindings() {
if binding.export {
self.env(binding.name.lexeme(), &binding.value);
}
}
2017-11-16 23:30:08 -08:00
}
}