Skip to main content

ralph/queue/operations/batch/
display.rs

1//! Batch operation result display utilities.
2//!
3//! Responsibilities:
4//! - Print batch operation results in a user-friendly format.
5//! - Handle both dry-run and actual execution output.
6//! - Display created task IDs for operations that generate tasks.
7//!
8//! Does not handle:
9//! - Actual batch operations (see update.rs, delete.rs, generate.rs, plan.rs).
10//! - Result calculation or aggregation.
11//!
12//! Assumptions/invariants:
13//! - Output goes to stdout via println!.
14//! - Dry run output clearly indicates no changes were made.
15
16use super::BatchOperationResult;
17
18/// Print batch operation results in a user-friendly format.
19pub fn print_batch_results(result: &BatchOperationResult, operation_name: &str, dry_run: bool) {
20    if dry_run {
21        println!(
22            "Dry run - would perform {} on {} tasks:",
23            operation_name, result.total
24        );
25        for r in &result.results {
26            if r.success {
27                println!("  - {}: would update", r.task_id);
28            } else {
29                println!(
30                    "  - {}: would fail - {}",
31                    r.task_id,
32                    r.error.as_deref().unwrap_or("unknown error")
33                );
34            }
35        }
36        println!("Dry run complete. No changes made.");
37        return;
38    }
39
40    // Collect created task IDs for operations that create tasks
41    let created_count: usize = result
42        .results
43        .iter()
44        .map(|r| r.created_task_ids.len())
45        .sum();
46
47    if result.has_failures() {
48        println!("{} completed with errors:", operation_name);
49        for r in &result.results {
50            if r.success {
51                println!("  ✓ {}: updated", r.task_id);
52                if !r.created_task_ids.is_empty() {
53                    for created_id in &r.created_task_ids {
54                        println!("    → Created: {}", created_id);
55                    }
56                }
57            } else {
58                println!(
59                    "  ✗ {}: failed - {}",
60                    r.task_id,
61                    r.error.as_deref().unwrap_or("unknown error")
62                );
63            }
64        }
65        println!(
66            "Completed: {}/{} tasks updated successfully.",
67            result.succeeded, result.total
68        );
69        if created_count > 0 {
70            println!("Created {} new tasks.", created_count);
71        }
72    } else {
73        println!("{} completed successfully:", operation_name);
74        for r in &result.results {
75            println!("  ✓ {}", r.task_id);
76            if !r.created_task_ids.is_empty() {
77                for created_id in &r.created_task_ids {
78                    println!("    → Created: {}", created_id);
79                }
80            }
81        }
82        println!("Updated {} tasks.", result.succeeded);
83        if created_count > 0 {
84            println!("Created {} new tasks.", created_count);
85        }
86    }
87}