Skip to content

Commit fcd8556

Browse files
authored
Merge pull request #94 from domenicquirl/pub-fn-to-command
Make `Cmd::to_command` public and add docs
2 parents 93fcf0e + 790df7a commit fcd8556

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,16 @@ impl Cmd {
10531053
})
10541054
}
10551055

1056-
fn to_command(&self) -> Command {
1056+
/// Constructs a [`std::process::Command`] for the same command as `self`.
1057+
///
1058+
/// The returned command will invoke the same program from the same working
1059+
/// directory and with the same environment as `self`. If the command was
1060+
/// set to [`ignore_stdout`](Cmd::ignore_stdout) or [`ignore_stderr`](Cmd::ignore_stderr),
1061+
/// this will apply to the returned command as well.
1062+
///
1063+
/// Other builder methods have no effect on the command returned since they
1064+
/// control how the command is run, but this method does not yet execute the command.
1065+
pub fn to_command(&self) -> Command {
10571066
let mut result = Command::new(&self.prog);
10581067
result.current_dir(&self.sh.cwd);
10591068
result.args(&self.args);

tests/it/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ fn smoke() {
3535
#[test]
3636
fn into_command() {
3737
let sh = setup();
38-
let _: std::process::Command = cmd!(sh, "git branch").into();
38+
let cmd = cmd!(sh, "git branch");
39+
let _ = cmd.to_command();
40+
let _: std::process::Command = cmd.into();
3941
}
4042

4143
#[test]

0 commit comments

Comments
 (0)