apicurio-cli 0.1.2

A powerful CLI tool for managing schema artifacts from Apicurio Registry with lockfile-based dependency management
use crate::{constants::APICURIO_LOCK, lockfile::LockFile};
use anyhow::{anyhow, Result};
use sha2::{Digest, Sha256};
use std::{fs, path::PathBuf};

pub async fn run() -> Result<()> {
    let lock = LockFile::load(&PathBuf::from(APICURIO_LOCK))?;
    let mut all_ok = true;

    for ld in &lock.locked_dependencies {
        let file = PathBuf::from(&ld.output_path);
        if !file.exists() {
            println!("❌ missing file for {}: {}", ld.name, file.display());
            all_ok = false;
            continue;
        }
        let data = fs::read(&file)?;
        let mut hasher = Sha256::new();
        hasher.update(&data);
        let sha = hex::encode(hasher.finalize());
        if sha != ld.sha256 {
            println!(
                "❌ hash mismatch {}: expected={}, got={}",
                ld.name, ld.sha256, sha
            );
            all_ok = false;
        } else {
            println!("✔️  {} OK", ld.name);
        }
    }

    if !all_ok {
        return Err(anyhow!("verification failed"));
    }
    Ok(())
}