1use super::*;
2
3pub trait CommandExt {
4 fn export(
5 &mut self,
6 settings: &Settings,
7 dotenv: &BTreeMap<String, String>,
8 scope: &Scope,
9 unexports: &HashSet<String>,
10 );
11
12 fn export_scope(&mut self, settings: &Settings, scope: &Scope, unexports: &HashSet<String>);
13}
14
15impl CommandExt for Command {
16 fn export(
17 &mut self,
18 settings: &Settings,
19 dotenv: &BTreeMap<String, String>,
20 scope: &Scope,
21 unexports: &HashSet<String>,
22 ) {
23 for (name, value) in dotenv {
24 self.env(name, value);
25 }
26
27 if let Some(parent) = scope.parent() {
28 self.export_scope(settings, parent, unexports);
29 }
30 }
31
32 fn export_scope(&mut self, settings: &Settings, scope: &Scope, unexports: &HashSet<String>) {
33 if let Some(parent) = scope.parent() {
34 self.export_scope(settings, parent, unexports);
35 }
36
37 for unexport in unexports {
38 self.env_remove(unexport);
39 }
40
41 for binding in scope.bindings() {
42 if binding.export || (settings.export && !binding.constant) {
43 self.env(binding.name.lexeme(), &binding.value);
44 }
45 }
46 }
47}