tsafe-cli 1.0.20

tsafe CLI — local secret and credential manager (replaces .env files)
Documentation
//! Snapshot list and restore command handler.
//!
//! Implements `tsafe snapshot list` and `tsafe snapshot restore` — listing
//! local vault snapshots and rolling back to the most recent one.

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(())
}