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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::{ffi::OsString, path::PathBuf, sync::Arc};
#[rustversion::attr(since(1.48), allow(clippy::rc_buffer))]
#[derive(Debug, Clone)]
pub struct Config {
pub(crate) arguments: Vec<OsString>,
pub(crate) log_command: bool,
pub(crate) working_directory: Option<PathBuf>,
pub(crate) added_environment_variables: Vec<(OsString, OsString)>,
pub(crate) stdin: Option<Arc<Vec<u8>>>,
pub(crate) capture_stdout: bool,
pub(crate) capture_stderr: bool,
pub(crate) error_on_non_zero_exit_code: bool,
}
impl Config {
pub(crate) fn full_command(&self) -> String {
let mut result = String::new();
for argument in self.arguments.iter() {
let argument = argument.to_string_lossy();
if !result.is_empty() {
result.push(' ');
}
let needs_quotes = argument.is_empty() || argument.contains(' ');
if needs_quotes {
result.push('\'');
}
result.push_str(&argument);
if needs_quotes {
result.push('\'');
}
}
result
}
}
impl Default for Config {
fn default() -> Self {
Config {
arguments: Vec::new(),
log_command: false,
working_directory: None,
added_environment_variables: Vec::new(),
stdin: None,
capture_stdout: false,
capture_stderr: false,
error_on_non_zero_exit_code: true,
}
}
}