Skip to content

Commit

Permalink
Clean-up/improve logging (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton authored Feb 6, 2024
1 parent ba5d66b commit 2e4958d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ members = [
"my-project",
"xtask",
]
resolver = "2"
4 changes: 2 additions & 2 deletions examples/demo/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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])?;
}
Expand Down
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.");
}
});
}

Expand Down

0 comments on commit 2e4958d

Please sign in to comment.