use std::path::PathBuf;
use clap::Parser;
use tencrypt_core::{CertMetrics, CertState, StateStore};
#[derive(Debug, Parser)]
#[command(name = "tencrypt-metrics-snapshot")]
#[command(about = "Print a CertMetrics JSON snapshot from a state file and exit")]
struct Cli {
#[arg(long)]
state_file: PathBuf,
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let store = StateStore::load(&cli.state_file)?;
let mut metrics = CertMetrics::default();
for record in &store.certs {
match record.state {
CertState::Issued => metrics.issued_total += 1,
CertState::Failed | CertState::Revoked => metrics.failed_total += 1,
_ => metrics.in_flight += 1,
}
}
println!("{}", serde_json::to_string_pretty(&metrics)?);
Ok(())
}