use crate::util::node_rpc;
use crate::{docs, fmt_ok, CommandGlobalOpts};
use clap::Args;
use colorful::Colorful;
use ockam::Context;
use ockam_api::cli_state::traits::StateDirTrait;
const LONG_ABOUT: &str = include_str!("./static/delete/long_about.txt");
const AFTER_LONG_HELP: &str = include_str!("./static/delete/after_long_help.txt");
#[derive(Clone, Debug, Args)]
#[command(
arg_required_else_help = true,
long_about = docs::about(LONG_ABOUT),
after_long_help = docs::after_help(AFTER_LONG_HELP)
)]
pub struct DeleteCommand {
name: String,
#[arg(display_order = 901, long, short)]
yes: bool,
}
impl DeleteCommand {
pub fn run(self, options: CommandGlobalOpts) {
node_rpc(run_impl, (options, self))
}
}
async fn run_impl(
_ctx: Context,
(opts, cmd): (CommandGlobalOpts, DeleteCommand),
) -> miette::Result<()> {
let state = opts.state;
let idt = state.identities.get(&cmd.name)?;
if opts
.terminal
.confirmed_with_flag_or_prompt(cmd.yes, "Are you sure you want to delete this identity?")?
{
state.delete_identity(idt)?;
opts.terminal
.stdout()
.plain(fmt_ok!(
"The identity named '{}' has been deleted",
&cmd.name
))
.machine(&cmd.name)
.json(serde_json::json!({ "name": &cmd.name }))
.write_line()?;
}
Ok(())
}