diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index f4e9511..76c266c 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -4,3 +4,4 @@ members = [ "my-project", "xtask", ] +resolver = "2" diff --git a/examples/demo/xtask/src/main.rs b/examples/demo/xtask/src/main.rs index 5879b22..db5380f 100644 --- a/examples/demo/xtask/src/main.rs +++ b/examples/demo/xtask/src/main.rs @@ -25,7 +25,7 @@ fn main() -> Result<()> { match opt { Opt::Watch { command, watch } => { - log::info!("starting to watch"); + log::info!("Starting to watch"); if !command.is_empty() { let mut it = command.iter(); @@ -42,7 +42,7 @@ fn main() -> Result<()> { let mut sleep = Command::new("bash"); sleep.arg("-c"); - sleep.arg("echo sleeping for 10 seconds...; sleep 10; echo sleep ended"); + sleep.arg("set -e; echo sleeping for 10 seconds...; sleep 10; echo sleep ended"); watch.run([check, test, sleep])?; } diff --git a/src/lib.rs b/src/lib.rs index ac292e2..7f770c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,7 @@ //! ## A basic implementation //! //! ```rust,no_run -//! use std::process::{Command, ExitStatus}; +//! use std::process::Command; //! use xtask_watch::{ //! anyhow::Result, //! clap, @@ -337,25 +337,26 @@ impl Watch { let mut current_child = current_child.clone(); let mut commands = commands.clone(); thread::spawn(move || { - commands.spawn(move |res| match res { + let mut status = ExitStatus::default(); + commands.spawn(|res| match res { Err(err) => { - log::error!("command failed: {err}"); + log::error!("Could not execute command: {err}"); false } Ok(child) => { log::trace!("new child: {}", child.id()); current_child.replace(child); - let status = current_child.wait(); - if status.success() { - true - } else if let Some(code) = status.code() { - log::error!("command failed: {:?}", code); - false - } else { - false - } + status = current_child.wait(); + status.success() } }); + if status.success() { + log::info!("Command succeeded."); + } else if let Some(code) = status.code() { + log::error!("Command failed (exit code: {code})"); + } else { + log::error!("Command failed."); + } }); }