use anyhow::Result;
use crate::run_registry::RunRegistry;
pub async fn execute(id: &str, force: bool) -> Result<()> {
let registry = RunRegistry::default();
match registry.get(id)? {
Some(state) => {
println!("🛑 Stopping Run: {}", id);
if state.status != bzzz_core::RunStatus::Running {
println!(" Already stopped: {:?}", state.status);
return Ok(());
}
if let Some(pid) = state.pid {
if state.is_process_alive() {
let signal = if force { "SIGKILL" } else { "SIGTERM" };
println!(" Sending {} to PID {}...", signal, pid);
match state.kill_process(force) {
Ok(()) => {
println!(" Process killed successfully");
}
Err(e) => {
println!(" Warning: Failed to kill process: {}", e);
}
}
} else {
println!(" Process already exited");
}
} else {
println!(" No PID to kill (run may have been in-memory)");
}
registry.mark_stopped(id, if force { "force stop" } else { "graceful stop" })?;
println!(" Status: Stopped");
}
None => {
println!("❌ Run not found: {}", id);
println!(" Tip: Use `bzzz list` to see all runs");
}
}
Ok(())
}