pub struct Execution { /* private fields */ }Expand description
The result of one run of an external command
The value holds the command that ran, the exit status of the command, what the command wrote to its standard output and to its standard error, and the time that the run took. It also holds the identifier that the operating system gave the command. The two streams stay apart, because a program separates its result from its diagnostics.
A status that is not a success is data. The check mode of a formatter ends
without success when it finds a file to format, and that is the answer
that the caller asked for. A caller that must not accept such a status
calls require_success.
§Examples
use kawauso_process::Invocation;
let execution = Invocation::new("git").arg("status").run().await?;
println!("{}", execution.stdout());Implementations§
Source§impl Execution
impl Execution
Sourcepub fn new(
invocation: Invocation,
id: Option<ProcessId>,
status: ExitStatus,
stdout: Capture,
stderr: Capture,
duration: Duration,
) -> Self
pub fn new( invocation: Invocation, id: Option<ProcessId>, status: ExitStatus, stdout: Capture, stderr: Capture, duration: Duration, ) -> Self
Creates the result of a run
A run builds this value, and a caller builds one where a test stands in for a command that no one starts. The identifier is the one that the operating system gave the command, and a result that no command produced carries none.
Sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
Returns the time that the run took
The time covers the whole run, from the start of the program to the end of the capture. A caller that reports a slow step, or that logs how long a tool ran, reads it here instead of measuring the call.
Sourcepub fn id(&self) -> Option<ProcessId>
pub fn id(&self) -> Option<ProcessId>
Returns the identifier that the operating system gave the command
An application that reports which program ran, or that writes the
identifier to a log, reads it here. The value is None when no run
produced the result, such as a result that a test built.
The command of a result has ended, and the operating system can give the identifier to another command. The value therefore names the command that ran. It does not name a command that runs now.
Sourcepub fn invocation(&self) -> &Invocation
pub fn invocation(&self) -> &Invocation
Returns the command that ran
Sourcepub fn require_success(self) -> Result<Self, RequireSuccessError>
pub fn require_success(self) -> Result<Self, RequireSuccessError>
Returns the result of a run that ended with success
A caller that must not accept a command that failed makes the check with this method instead of reading the status itself. The result travels on, so a caller can take the output of the command from it.
§Errors
Returns UnsuccessfulCommand when the command ended
without success. The error names the command, the status, and what the
command wrote to its standard error, which is where a program states
why it stopped.
§Examples
use kawauso_process::Invocation;
let execution = Invocation::new("git")
.arg("rev-parse")
.arg("HEAD")
.run()
.await?
.require_success()?;
let commit = execution.stdout().to_string_lossy().trim().to_owned();Sourcepub fn status(&self) -> ExitStatus
pub fn status(&self) -> ExitStatus
Returns the status with which the command ended
A status that is not a success is a normal result. A command that ran and failed reports its failure here, and the run itself returns an error only when the command could not run at all.