relay-cli 0.1.2

CLI interface for Relay Agents.
use crate::{progress::Progress, storage::Storage};

#[derive(Debug, Clone, clap::Parser)]
#[clap(about = "Delete all local data irreversibly")]
pub struct WipeoutCmd {
    #[clap(long, default_value_t = false)]
    pub yes: bool,

    #[clap(long, default_value_t = false)]
    pub delete_everything: bool,
}

impl WipeoutCmd {
    pub fn execute(&self, storage: &mut Storage) -> anyhow::Result<()> {
        let mut progress = Progress::new(false);

        if !self.yes {
            progress.warn("Wipeout deletes ALL DATA.");
            progress.warn("Are you sure? Run with --yes to confirm.");
            progress.abort("Wipeout aborted");
        }

        if !self.delete_everything {
            progress.error("Whipeout DELETES PRIVATE KEYS which are IMPOSSIBLE TO RECOVER.");
            progress.error("Are you REALLY sure? Run with --delete-everything to confirm.");
            progress.abort("Wipeout aborted");
        }

        progress.step("Deleting storage", "Storage deleted");
        storage.delete()?;

        progress.step("Resseting storage", "Storage reset");
        storage.reset();

        progress.commit();

        progress.arrow("All data wiped out.");
        progress.nested(1, "Uninstall the CLI for full cleanup.");

        Ok(())
    }
}