3 unstable releases

0.2.1 Jul 21, 2025
0.2.0 Feb 16, 2024
0.1.0 Jan 5, 2024

#158 in Debugging

Download history 4418/week @ 2025-07-12 5285/week @ 2025-07-19 3840/week @ 2025-07-26 5596/week @ 2025-08-02 5485/week @ 2025-08-09 5478/week @ 2025-08-16 5270/week @ 2025-08-23 4311/week @ 2025-08-30 5774/week @ 2025-09-06 5127/week @ 2025-09-13 4557/week @ 2025-09-20 3512/week @ 2025-09-27 4754/week @ 2025-10-04 4873/week @ 2025-10-11 4479/week @ 2025-10-18 4982/week @ 2025-10-25

19,465 downloads per month
Used in 13 crates (4 directly)

MIT/Apache

17KB
253 lines

axoprocess

crates.io docs Rust CI

Nicer defaults for invoking CLI Commands.

License

Licensed under either of

at your option.


lib.rs:

Nicer defaults for invoking CLI Commands.

[Cmd][] is a wrapper around std::process::Command with largely the same API except we want to be able to:

  • Produce nicer errors that explain what was being run (using thiserror/miette)
  • Log every time the command is executed (defaults tracing::info!)
  • Automatically check the return status's success() (can be opted-out per Cmd)

If you like the defaults then mostly all you need to know is that Cmd::new takes a second argument for "what should I tell the user this Command was trying to do at a high level".

This lets us turn the following logic:

#
let mut cmd = Command::new("cargo");
cmd.arg("-V");

info!("exec {:?}", cmd);

let output = cmd.output()
  .map_err(|cause| MyCmdError {
      desc: "failed to get your cargo toolchain's version",
      cause
  })?;

if !output.status.success() {
    Err(MyStatusError {
        desc: "failed to get your cargo toolchain's version",
        status: output.status
    })?;
}

println!("version was {}", String::from_utf8_lossy(&output.stdout));

Into this:

let output = Cmd::new("cargo", "get your cargo toolchain's version")
  .arg("-V")
  .output()?;

println!("version was {}", String::from_utf8_lossy(&output.stdout));

Which is, a lot nicer!

Dependencies

~2–2.8MB
~46K SLoC