1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::common::*;

pub(crate) trait CommandExt {
  fn export_environment_variables<'a>(
    &mut self,
    scope: &BTreeMap<&'a str, (bool, String)>,
    dotenv: &BTreeMap<String, String>,
  ) -> RunResult<'a, ()>;
}

impl CommandExt for Command {
  fn export_environment_variables<'a>(
    &mut self,
    scope: &BTreeMap<&'a str, (bool, String)>,
    dotenv: &BTreeMap<String, String>,
  ) -> RunResult<'a, ()> {
    for (name, value) in dotenv {
      self.env(name, value);
    }

    for (name, (export, value)) in scope {
      if *export {
        self.env(name, value);
      }
    }

    Ok(())
  }
}