Skip to content

Commit

Permalink
make Cmd::to_command public and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Domenic Quirl authored and Domenic Quirl committed Jul 19, 2024
1 parent 7242531 commit 30fdd04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 30fdd04

Please sign in to comment.