scud/commands/
stats.rs

1use anyhow::Result;
2use colored::Colorize;
3use std::path::PathBuf;
4
5use crate::commands::helpers::resolve_group_tag;
6use crate::storage::Storage;
7
8pub fn run(project_root: Option<PathBuf>, tag: Option<&str>) -> Result<()> {
9    let storage = Storage::new(project_root);
10
11    let phase_tag = resolve_group_tag(&storage, tag, true)?;
12    let tasks = storage.load_tasks()?;
13    let phase = tasks
14        .get(&phase_tag)
15        .ok_or_else(|| anyhow::anyhow!("Phase '{}' not found", phase_tag))?;
16    let active_phase = &phase.name;
17
18    let stats = phase.get_stats();
19
20    let completion_pct = if stats.total > 0 {
21        (stats.done as f32 / stats.total as f32 * 100.0) as u32
22    } else {
23        0
24    };
25
26    println!(
27        "\n{} {}",
28        "Phase Statistics:".blue().bold(),
29        active_phase.green()
30    );
31    println!("{}", "=================".blue());
32    println!();
33    println!("{:<20} {}", "Total Tasks:".yellow(), stats.total);
34    println!("{:<20} {}", "Pending:".yellow(), stats.pending);
35    println!("{:<20} {}", "In Progress:".yellow(), stats.in_progress);
36    println!(
37        "{:<20} {}",
38        "Done:".yellow(),
39        stats.done.to_string().green()
40    );
41    println!(
42        "{:<20} {}",
43        "Blocked:".yellow(),
44        stats.blocked.to_string().red()
45    );
46    println!();
47    println!(
48        "{:<20} {}",
49        "Total Complexity:".yellow(),
50        stats.total_complexity
51    );
52    println!(
53        "{:<20} {}%",
54        "Completion:".yellow(),
55        completion_pct.to_string().green()
56    );
57
58    // Show progress bar
59    let bar_length = 50;
60    let filled = (completion_pct as f32 / 100.0 * bar_length as f32) as usize;
61    let empty = bar_length - filled;
62    let bar = format!("[{}{}]", "=".repeat(filled).green(), " ".repeat(empty));
63    println!("\n{}", bar);
64    println!();
65
66    Ok(())
67}