pub trait CommandExt {
// Required methods
fn inherit(&mut self) -> &mut Self;
fn log(&mut self) -> &mut Self;
fn print(&mut self) -> &mut Self;
fn display(&self) -> String;
fn result(&mut self) -> CommandResult;
}
Expand description
Adds useful extension methods to the Command
type
Required Methods§
Sourcefn inherit(&mut self) -> &mut Self
fn inherit(&mut self) -> &mut Self
Inherit both stdout
and stderr
from this process.
§Example
use std::process::Command;
use fluvio_command::CommandExt;
let _ = Command::new("echo")
.arg("Hello world")
.inherit()
.status();
Sourcefn log(&mut self) -> &mut Self
fn log(&mut self) -> &mut Self
Print a stringified version of the Command to the debug log.
§Example
use std::process::Command;
use fluvio_command::CommandExt;
let _ = Command::new("echo")
.arg("How are you Fluvio")
.log()
.spawn();
Sourcefn print(&mut self) -> &mut Self
fn print(&mut self) -> &mut Self
Print a stringified version of the Command to stdout.
§Example
use std::process::Command;
use fluvio_command::CommandExt;
let _ = Command::new("echo")
.arg("How are you Fluvio")
.print()
.spawn();
Sourcefn display(&self) -> String
fn display(&self) -> String
Return a stringified version of the Command.
§Example
use std::process::Command;
use fluvio_command::CommandExt;
let mut command = Command::new("echo");
command.arg("one").arg("two three");
let command_string: String = command.display();
assert_eq!(command_string, "echo one two three");
Sourcefn result(&mut self) -> CommandResult
fn result(&mut self) -> CommandResult
Returns a result signaling the outcome of executing this command.
§Example
use std::process::{Command, Output};
use fluvio_command::{CommandExt, CommandErrorKind};
// On success, we get the stdout and stderr output
let output: Output = Command::new("true").result().unwrap();
let error = Command::new("bash")
.args(&["-c", r#"echo "this command failed with this stderr" 1>&2 && false"#])
.result()
.unwrap_err();
if let CommandErrorKind::ExitError(1i32, output) = error.source {
assert_eq!(
String::from_utf8_lossy(&output.stderr).to_string(),
"this command failed with this stderr\n",
);
} else {
panic!("should fail with stderr output");
}
let error = Command::new("foobar").result().unwrap_err();
assert!(matches!(error.source, CommandErrorKind::IoError(_)));
assert_eq!(error.command, "foobar");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.