use std::str::FromStr;
use anyhow::Result;
use clap::{ArgMatches, Args, FromArgMatches, Parser, Subcommand};
use arti_client::{InertTorClient, TorClient, TorClientConfig};
use tor_keymgr::KeystoreId;
use tor_rtcompat::Runtime;
#[derive(Debug, Parser)]
pub(crate) enum RawSubcommands {
#[command(subcommand)]
KeysRaw(RawSubcommand),
}
#[derive(Subcommand, Debug, Clone)]
pub(crate) enum RawSubcommand {
RemoveById(RemoveByIdArgs),
}
#[derive(Debug, Clone, Args)]
pub(crate) struct RemoveByIdArgs {
raw_entry_id: String,
#[arg(short, long, default_value_t = String::from("arti"))]
keystore_id: String,
}
pub(crate) fn run<R: Runtime>(
runtime: R,
keys_matches: &ArgMatches,
config: &TorClientConfig,
) -> Result<()> {
let subcommand =
RawSubcommand::from_arg_matches(keys_matches).expect("Could not parse keys subcommand");
let client = TorClient::with_runtime(runtime)
.config(config.clone())
.create_inert()?;
match subcommand {
RawSubcommand::RemoveById(args) => run_raw_remove(&args, &client),
}
}
fn run_raw_remove(args: &RemoveByIdArgs, client: &InertTorClient) -> Result<()> {
let keymgr = client.keymgr()?;
let keystore_id = KeystoreId::from_str(&args.keystore_id)?;
keymgr.remove_unchecked(&args.raw_entry_id, &keystore_id)?;
Ok(())
}