just/src/command_ext.rs

32 lines
831 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, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope);
fn export_scope(&mut self, settings: &Settings, scope: &Scope);
2017-11-16 23:30:08 -08:00
}
impl CommandExt for Command {
fn export(&mut self, settings: &Settings, 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(settings, parent);
2017-11-16 23:30:08 -08:00
}
}
fn export_scope(&mut self, settings: &Settings, scope: &Scope) {
if let Some(parent) = scope.parent() {
self.export_scope(settings, parent);
}
for binding in scope.bindings() {
if settings.export || binding.export {
self.env(binding.name.lexeme(), &binding.value);
}
}
2017-11-16 23:30:08 -08:00
}
}