Skip to main content

aprender_contracts_cli/commands/
diff.rs

1use std::path::Path;
2
3use provable_contracts::diff::{diff_contracts, is_identical};
4use provable_contracts::schema::parse_contract;
5
6pub fn run(old_path: &Path, new_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
7    let old = parse_contract(old_path)?;
8    let new = parse_contract(new_path)?;
9
10    let diff = diff_contracts(&old, &new);
11
12    if is_identical(&diff) {
13        println!("Contracts are identical.");
14        return Ok(());
15    }
16
17    println!(
18        "Contract diff: v{} → v{}",
19        diff.old_version, diff.new_version
20    );
21    println!("Suggested bump: {}", diff.suggested_bump);
22    println!();
23
24    for section in &diff.sections {
25        if section.is_empty() {
26            continue;
27        }
28        println!("  {}:", section.section);
29        for a in &section.added {
30            println!("    + {a}");
31        }
32        for r in &section.removed {
33            println!("    - {r}");
34        }
35        for c in &section.changed {
36            println!("    ~ {c}");
37        }
38    }
39
40    Ok(())
41}