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.
22 #![deny(rust_2018_idioms, missing_docs)]
33 #![forbid(unsafe_code)]
44
@@ -15,7 +15,7 @@ pub struct Prepare { · 10 unmodified lines
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 { · 27 unmodified lines
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 }

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