diva

The continuation of bossy, an opinionated convenience wrappers for std::process::Command and friends.
use diva::Command;
use std::{io::Write as _, path::Path};
fn main() -> diva::Result<()> {
simple_logger::init().unwrap();
let path = Path::new("src");
println!("{path:?} directory contents:");
let status = Command::parse("ls -l")
.with_arg(path)
.run_and_wait()?;
println!("exited with code {:?}", status.code());
let readme_output = Command::parse("cat README.md")
.run_and_wait_for_output()?;
println!(
"README.md contents:\n{}",
readme_output
.stdout_str()
.expect("README.md contained invalid utf-8")
);
let mut handle = Command::new("shasum")
.with_stdin_piped()
.with_stdout_piped()
.with_stderr_piped()
.run()?;
handle
.stdin()
.expect("developer error: `handle` stdin not captured")
.write_all(readme_output.stdout())
.expect("failed to write to `handle` stdin");
let shasum_output = handle.wait_for_output()?;
println!(
"README.md SHA-1 sum: {}",
shasum_output
.stdout_str()
.expect("shasum output contained invalid utf-8")
);
Ok(())
}
You can run the example to see the exact same code as above, but like, with output:
cargo run --example commands
There isn't a ton of documentation, but this is a pretty thin wrapper, so documentation for std::process will typically apply here as well.