Showing the changes to git-command/src (1 of 2 files). Show all
Unified · Split
| @@ -10,6 +10,7 @@ pub struct Prepare { · 9 unmodified lines | ||
| 10 | 10 | stdin: std::process::Stdio, |
| 11 | 11 | stdout: std::process::Stdio, |
| 12 | 12 | stderr: std::process::Stdio, |
| 13 | + args: Vec<OsString>, | |
| 13 | 14 | use_shell: bool, |
| 14 | 15 | } |
| 15 | 16 | |
| @@ -43,6 +44,12 @@ mod prepare { · 27 unmodified lines | ||
| 43 | 44 | self.stderr = stdio; |
| 44 | 45 | self |
| 45 | 46 | } |
| 47 | + | |
| 48 | + /// Add `arg` to the list of arguments to call the command with. | |
| 49 | + pub fn arg(mut self, arg: impl Into<std::ffi::OsString>) -> Self { | |
| 50 | + self.args.push(arg.into()); | |
| 51 | + self | |
| 52 | + } | |
| 46 | 53 | } |
| 47 | 54 | |
| 48 | 55 | /// Finalization |
| @@ -55,16 +62,23 @@ mod prepare { · 6 unmodified lines | ||
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | impl Into<Command> for Prepare { |
| 58 | − fn into(self) -> Command { | |
| 65 | + fn into(mut self) -> Command { | |
| 59 | 66 | let mut cmd = if self.use_shell { |
| 60 | 67 | let mut cmd = Command::new(if cfg!(windows) { "sh" } else { "/bin/sh" }); |
| 61 | 68 | cmd.arg("-c"); |
| 69 | + if !self.args.is_empty() { | |
| 70 | + self.command.push(" \"$@\"") | |
| 71 | + } | |
| 62 | 72 | cmd.arg(self.command); |
| 73 | + cmd.arg("--"); | |
| 63 | 74 | cmd |
| 64 | 75 | } else { |
| 65 | 76 | Command::new(self.command) |
| 66 | 77 | }; |
| 67 | − cmd.stdin(self.stdin).stdout(self.stdout).stderr(self.stderr); | |
| 78 | + cmd.stdin(self.stdin) | |
| 79 | + .stdout(self.stdout) | |
| 80 | + .stderr(self.stderr) | |
| 81 | + .args(self.args); | |
| 68 | 82 | cmd |
| 69 | 83 | } |
| 70 | 84 | } |
| @@ -83,6 +97,7 @@ pub fn prepare(cmd: impl Into<OsString>) -> Prepare { · 12 unmodified lines | ||
| 83 | 97 | stdin: std::process::Stdio::null(), |
| 84 | 98 | stdout: std::process::Stdio::piped(), |
| 85 | 99 | stderr: std::process::Stdio::null(), |
| 100 | + args: Vec::new(), | |
| 86 | 101 | use_shell: false, |
| 87 | 102 | } |
| 88 | 103 | } |