Wraps a command to run with environment variables forwarded. # Returns Returns a tuple of (CommandBuilder, NamedTempFile) where: - CommandBuilder is wrapped with bash to source the environment and run the original command - NamedTempFile is the environment file that must be kept alive until command execution
(
mut cmd_builder: CommandBuilder,
extra_env: &HashMap<String, String>,
)
| 33 | /// - CommandBuilder is wrapped with bash to source the environment and run the original command |
| 34 | /// - NamedTempFile is the environment file that must be kept alive until command execution |
| 35 | pub fn wrap_with_env( |
| 36 | mut cmd_builder: CommandBuilder, |
| 37 | extra_env: &HashMap<String, String>, |
| 38 | ) -> Result<(CommandBuilder, NamedTempFile)> { |
| 39 | let env_file = create_env_file(extra_env)?; |
| 40 | |
| 41 | // Create bash command that sources the env file and runs the original command |
| 42 | let original_command = cmd_builder.as_command_line(); |
| 43 | let bash_command = format!( |
| 44 | "source {} && {}", |
| 45 | env_file.path().display(), |
| 46 | original_command |
| 47 | ); |
| 48 | cmd_builder.wrap("bash", ["-c", &bash_command]); |
| 49 | |
| 50 | Ok((cmd_builder, env_file)) |
| 51 | } |
| 52 | |
| 53 | fn create_env_file(extra_env: &HashMap<String, String>) -> Result<NamedTempFile> { |
| 54 | let system_env = get_exported_system_env()?; |
no test coverage detected