Skip to content

Commit

Permalink
Merge pull request #94 from domenicquirl/pub-fn-to-command
Browse files Browse the repository at this point in the history
Make `Cmd::to_command` public and add docs
  • Loading branch information
matklad authored Dec 23, 2024
2 parents 93fcf0e + 790df7a commit fcd8556
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 @@ -1053,7 +1053,16 @@ impl Cmd {
})
}

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 result = Command::new(&self.prog);
result.current_dir(&self.sh.cwd);
result.args(&self.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 @@ -35,7 +35,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 fcd8556

Please sign in to comment.