use anyhow::Result;
use colored::Colorize;
use tsafe_cli::cli::SnapshotAction;
use tsafe_core::{profile, snapshot};
pub(crate) fn cmd_snapshot(profile: &str, action: SnapshotAction) -> Result<()> {
match action {
SnapshotAction::List => {
let snaps = snapshot::list(profile)?;
if snaps.is_empty() {
println!("{} No snapshots found for profile '{profile}'", "i".blue());
return Ok(());
}
println!(
"{} {} snapshot(s) for profile '{profile}':",
"i".blue(),
snaps.len()
);
for p in &snaps {
println!(" {}", p.display());
}
}
SnapshotAction::Restore => {
let path = profile::vault_path(profile);
let snap = snapshot::restore_latest(&path, profile)?;
println!(
"{} Vault restored from snapshot: {}",
"✓".green(),
snap.display()
);
println!(
"{} Verify secrets with: tsafe --profile {profile} list",
"i".blue()
);
}
}
Ok(())
}