History

Add a way to transform a `Prepare` into a `Command` for even more flexibility (#450)

Sebastian Thiel committed 4 years ago

Commit eeedd2c1 parent 1322f721 file · +12 −5Browse files

Showing the changes to git-command/src (1 of 1 file). Show all

Unified · Split

git-command/src/lib.rs+12−5
@@ -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.
2#![deny(rust_2018_idioms, missing_docs)]2#![deny(rust_2018_idioms, missing_docs)]
3#![forbid(unsafe_code)]3#![forbid(unsafe_code)]
4 4
@@ -15,7 +15,7 @@ pub struct Prepare { · 10 unmodified lines
15 15
16mod prepare {16mod prepare {
17 use crate::Prepare;17 use crate::Prepare;
18 use std::process::Stdio;18 use std::process::{Command, Stdio};
19 19
20 /// Builder20 /// Builder
21 impl Prepare {21 impl Prepare {
@@ -49,16 +49,23 @@ mod prepare { · 27 unmodified lines
49 impl Prepare {49 impl Prepare {
50 /// Spawn the command as configured.50 /// Spawn the command as configured.
51 pub fn spawn(self) -> std::io::Result<std::process::Child> {51 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 {
52 let mut cmd = if self.use_shell {59 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" });
54 cmd.arg("-c");61 cmd.arg("-c");
55 cmd.arg(self.command);62 cmd.arg(self.command);
56 cmd63 cmd
57 } else {64 } else {
58 std::process::Command::new(self.command)65 Command::new(self.command)
59 };66 };
60 cmd.stdin(self.stdin).stdout(self.stdout).stderr(self.stderr);67 cmd.stdin(self.stdin).stdout(self.stdout).stderr(self.stderr);
61 cmd.spawn()68 cmd
62 }69 }
63 }70 }
64}71}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t