use std::process::Command;
pub(crate) fn run() -> Result<(), String> {
let probe = Command::new("cargo").args(["watch", "--version"]).output();
match probe {
Ok(out) if out.status.success() => {}
_ => {
return Err("`cargo-watch` isn't installed. Install once with:\n \
cargo install cargo-watch\n\
Then re-run `rustio reload`."
.into());
}
}
println!("rustio reload — running `cargo watch -x run` (Ctrl-C to stop)…");
let status = Command::new("cargo")
.args(["watch", "-x", "run"])
.status()
.map_err(|e| format!("spawn cargo watch: {e}"))?;
if status.success() {
Ok(())
} else {
Err(format!(
"cargo watch exited with status {}",
status
.code()
.map(|c| c.to_string())
.unwrap_or_else(|| "(signal)".into())
))
}
}