Skip to content

Commit eeedd2c

Browse files
committed
Add a way to transform a Prepare into a Command for even more flexibility (#450)
1 parent 1322f72 commit eeedd2c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

git-command/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Launch commands very similarly to `std::process::Command`, but with `git` specific capabilities and adjustments.
1+
//! Launch commands very similarly to `Command`, but with `git` specific capabilities and adjustments.
22
#![deny(rust_2018_idioms, missing_docs)]
33
#![forbid(unsafe_code)]
44

@@ -15,7 +15,7 @@ pub struct Prepare {
1515

1616
mod prepare {
1717
use crate::Prepare;
18-
use std::process::Stdio;
18+
use std::process::{Command, Stdio};
1919

2020
/// Builder
2121
impl Prepare {
@@ -49,16 +49,23 @@ mod prepare {
4949
impl Prepare {
5050
/// Spawn the command as configured.
5151
pub fn spawn(self) -> std::io::Result<std::process::Child> {
52+
let mut cmd: Command = self.into();
53+
cmd.spawn()
54+
}
55+
}
56+
57+
impl Into<Command> for Prepare {
58+
fn into(self) -> Command {
5259
let mut cmd = if self.use_shell {
53-
let mut cmd = std::process::Command::new(if cfg!(windows) { "sh" } else { "/bin/sh" });
60+
let mut cmd = Command::new(if cfg!(windows) { "sh" } else { "/bin/sh" });
5461
cmd.arg("-c");
5562
cmd.arg(self.command);
5663
cmd
5764
} else {
58-
std::process::Command::new(self.command)
65+
Command::new(self.command)
5966
};
6067
cmd.stdin(self.stdin).stdout(self.stdout).stderr(self.stderr);
61-
cmd.spawn()
68+
cmd
6269
}
6370
}
6471
}

0 commit comments

Comments
 (0)