1 use crate::common::*;
2 
3 pub(crate) trait CommandExt {
export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope)4   fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope);
5 
export_scope(&mut self, settings: &Settings, scope: &Scope)6   fn export_scope(&mut self, settings: &Settings, scope: &Scope);
7 }
8 
9 impl CommandExt for Command {
export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope)10   fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope) {
11     for (name, value) in dotenv {
12       self.env(name, value);
13     }
14 
15     if let Some(parent) = scope.parent() {
16       self.export_scope(settings, parent);
17     }
18   }
19 
export_scope(&mut self, settings: &Settings, scope: &Scope)20   fn export_scope(&mut self, settings: &Settings, scope: &Scope) {
21     if let Some(parent) = scope.parent() {
22       self.export_scope(settings, parent);
23     }
24 
25     for binding in scope.bindings() {
26       if settings.export || binding.export {
27         self.env(binding.name.lexeme(), &binding.value);
28       }
29     }
30   }
31 }
32