2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) trait CommandExt {
|
2021-03-25 17:00:32 -07:00
|
|
|
fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope);
|
2019-12-07 03:09:21 -08:00
|
|
|
|
2021-03-25 17:00:32 -07:00
|
|
|
fn export_scope(&mut self, settings: &Settings, scope: &Scope);
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CommandExt for Command {
|
2021-03-25 17:00:32 -07:00
|
|
|
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);
|
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
|
2019-12-07 03:09:21 -08:00
|
|
|
if let Some(parent) = scope.parent() {
|
2021-03-25 17:00:32 -07:00
|
|
|
self.export_scope(settings, parent);
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-12-07 03:09:21 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
|
2021-03-25 17:00:32 -07:00
|
|
|
fn export_scope(&mut self, settings: &Settings, scope: &Scope) {
|
2019-12-07 03:09:21 -08:00
|
|
|
if let Some(parent) = scope.parent() {
|
2021-03-25 17:00:32 -07:00
|
|
|
self.export_scope(settings, parent);
|
2019-12-07 03:09:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for binding in scope.bindings() {
|
2021-03-25 17:00:32 -07:00
|
|
|
if settings.export || binding.export {
|
2019-12-07 03:09:21 -08:00
|
|
|
self.env(binding.name.lexeme(), &binding.value);
|
|
|
|
}
|
|
|
|
}
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|