use anyhow::Result;
use crate::run_registry::RunRegistry;
pub async fn execute(id: &str) -> Result<()> {
let registry = RunRegistry::default();
match registry.get(id)? {
Some(mut state) => {
println!("📊 Status for Run: {}", id);
if state.status == bzzz_core::RunStatus::Running {
if let Some(pid) = state.pid {
if state.is_process_alive() {
println!(" PID: {} (running)", pid);
} else {
println!(" PID: {} (exited)", pid);
state.status = bzzz_core::RunStatus::Completed;
registry.update_status(id, state.status)?;
}
} else {
println!(" PID: N/A");
}
} else {
if let Some(pid) = state.pid {
println!(" PID: {}", pid);
}
}
println!(" Status: {:?}", state.status);
println!(" Runtime: {:?}", state.runtime_kind);
println!(" Spec: {}", state.spec_path.display());
let elapsed = state.started_at.elapsed()?;
let secs = elapsed.as_secs();
let mins = secs / 60;
let hours = mins / 60;
if hours > 0 {
println!(" Elapsed: {}h {}m {}s", hours, mins % 60, secs % 60);
} else if mins > 0 {
println!(" Elapsed: {}m {}s", mins, secs % 60);
} else {
println!(" Elapsed: {}s", secs);
}
println!(" Working Dir: {}", state.working_dir.display());
}
None => {
println!("❌ Run not found: {}", id);
println!(" Tip: Use `bzzz list` to see all runs");
}
}
Ok(())
}