Skip to main content

batuta/stack/publish_status/
format.rs

1//! Report formatting utilities.
2//!
3//! Provides text and JSON formatting for publish status reports.
4
5use anyhow::Result;
6
7use super::types::PublishStatusReport;
8
9// ============================================================================
10// PUB-007: Display Formatting
11// ============================================================================
12
13/// Format report as text table
14pub fn format_report_text(report: &PublishStatusReport) -> String {
15    use std::fmt::Write;
16
17    let mut out = String::new();
18
19    // Header
20    writeln!(
21        out,
22        "{:<20} {:>10} {:>10} {:>10} {:>12}",
23        "Crate", "Local", "crates.io", "Git", "Action"
24    )
25    .ok();
26    writeln!(out, "{}", "─".repeat(65)).ok();
27
28    // Rows
29    for status in &report.crates {
30        let local = status.local_version.as_deref().unwrap_or("-");
31        let remote = status.crates_io_version.as_deref().unwrap_or("-");
32        let git = status.git_status.summary();
33
34        writeln!(
35            out,
36            "{:<20} {:>10} {:>10} {:>10} {:>2} {:>9}",
37            status.name,
38            local,
39            remote,
40            git,
41            status.action.symbol(),
42            status.action.description()
43        )
44        .ok();
45    }
46
47    writeln!(out, "{}", "─".repeat(65)).ok();
48
49    // Summary
50    writeln!(out).ok();
51    writeln!(
52        out,
53        "\u{1F4CA} {} crates: {} publish, {} commit, {} up-to-date",
54        report.total, report.needs_publish, report.needs_commit, report.up_to_date
55    )
56    .ok();
57    writeln!(
58        out,
59        "\u{26A1} {}ms (cache: {} hits, {} misses)",
60        report.elapsed_ms, report.cache_hits, report.cache_misses
61    )
62    .ok();
63
64    out
65}
66
67/// Format report as JSON
68pub fn format_report_json(report: &PublishStatusReport) -> Result<String> {
69    Ok(serde_json::to_string_pretty(report)?)
70}