From 30fdd044b7be2c6f221fd5661e66c70db7e479fb Mon Sep 17 00:00:00 2001 From: Domenic Quirl Date: Fri, 19 Jul 2024 14:25:57 +0200 Subject: [PATCH] make `Cmd::to_command` public and add docs --- src/lib.rs | 11 ++++++++++- tests/it/main.rs | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9a7ccda..de213f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1048,7 +1048,16 @@ impl<'a> Cmd<'a> { Ok(output) } - fn to_command(&self) -> Command { + /// Constructs a [`std::process::Command`] for the same command as `self`. + /// + /// The returned command will invoke the same program from the same working + /// directory and with the same environment as `self`. If the command was + /// set to [`ignore_stdout`](Cmd::ignore_stdout) or [`ignore_stderr`](Cmd::ignore_stderr), + /// this will apply to the returned command as well. + /// + /// Other builder methods have no effect on the command returned since they + /// control how the command is run, but this method does not yet execute the command. + pub fn to_command(&self) -> Command { let mut res = Command::new(&self.data.prog); res.current_dir(self.shell.current_dir()); res.args(&self.data.args); diff --git a/tests/it/main.rs b/tests/it/main.rs index 3214840..fa8638d 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -36,7 +36,9 @@ fn smoke() { #[test] fn into_command() { let sh = setup(); - let _: std::process::Command = cmd!(sh, "git branch").into(); + let cmd = cmd!(sh, "git branch"); + let _ = cmd.to_command(); + let _: std::process::Command = cmd.into(); } #[test]