Include cmdline in error display; show cargo install progress

This commit is contained in:
Damien Elmes 2023-06-17 14:45:31 +10:00
parent dd95f6f749
commit 93da201f07
4 changed files with 17 additions and 14 deletions

1
Cargo.lock generated
View file

@ -2345,6 +2345,7 @@ dependencies = [
"camino", "camino",
"once_cell", "once_cell",
"walkdir", "walkdir",
"which",
] ]
[[package]] [[package]]

View file

@ -12,14 +12,14 @@ use snafu::Snafu;
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
pub enum Error { pub enum Error {
#[snafu(display("Failed to execute: {cmdline}"))]
DidNotExecute { DidNotExecute {
cmdline: String, cmdline: String,
source: std::io::Error, source: std::io::Error,
}, },
ReturnedError { #[snafu(display("Fail with code {code:?}: {cmdline}"))]
cmdline: String, ReturnedError { cmdline: String, code: Option<i32> },
code: Option<i32>, #[snafu(display("Couldn't decode stdout/stderr as utf8"))]
},
InvalidUtf8 { InvalidUtf8 {
cmdline: String, cmdline: String,
source: FromUtf8Error, source: FromUtf8Error,
@ -110,13 +110,12 @@ mod test {
#[test] #[test]
fn test_run() { fn test_run() {
assert!(matches!( assert_eq!(
Command::run(["fakefake", "1", "2"]), Command::run(["fakefake", "1", "2"])
Err(Error::DidNotExecute { .unwrap_err()
cmdline, .to_string(),
.. "Failed to execute: fakefake 1 2"
}) if cmdline == "fakefake 1 2" );
));
#[cfg(not(windows))] #[cfg(not(windows))]
assert!(matches!( assert!(matches!(
Command::new("false").ensure_success(), Command::new("false").ensure_success(),

View file

@ -15,3 +15,4 @@ anyhow = "1.0.71"
camino = "1.1.4" camino = "1.1.4"
once_cell = "1.17.1" once_cell = "1.17.1"
walkdir = "2.3.3" walkdir = "2.3.3"
which = "4.4.0"

View file

@ -198,13 +198,13 @@ impl LintContext {
} }
fn check_cargo_deny() -> Result<()> { fn check_cargo_deny() -> Result<()> {
Command::run(["cargo", "install", "-q", "cargo-deny@0.13.5"])?; Command::run(["cargo", "install", "cargo-deny@0.13.5"])?;
Command::run(["cargo", "deny", "check", "-A", "duplicate"])?; Command::run(["cargo", "deny", "check", "-A", "duplicate"])?;
Ok(()) Ok(())
} }
fn update_hakari() -> Result<()> { fn update_hakari() -> Result<()> {
Command::run(["cargo", "install", "-q", "cargo-hakari@0.9.23"])?; Command::run(["cargo", "install", "cargo-hakari@0.9.23"])?;
Command::run(["cargo", "hakari", "generate"])?; Command::run(["cargo", "hakari", "generate"])?;
Ok(()) Ok(())
} }
@ -257,7 +257,9 @@ fn check_for_unstaged_changes() {
} }
fn generate_licences() -> Result<String> { fn generate_licences() -> Result<String> {
Command::run(["cargo", "install", "-q", "cargo-license@0.5.1"])?; if which::which("cargo-license").is_err() {
Command::run(["cargo", "install", "cargo-license@0.5.1"])?;
}
let output = Command::run_with_output([ let output = Command::run_with_output([
"cargo-license", "cargo-license",
"--features", "--features",