use dialoguer::Confirm;
use is_terminal::IsTerminal;
use crate::{cmd::AsyncCliCommand, ApiOpts};
use super::AppIdent;
#[derive(clap::Parser, Debug)]
pub struct CmdAppDelete {
#[clap(flatten)]
api: ApiOpts,
#[clap(long)]
non_interactive: bool,
ident: AppIdent,
}
impl CmdAppDelete {
async fn run(self) -> Result<(), anyhow::Error> {
let interactive = std::io::stdin().is_terminal() && !self.non_interactive;
let client = self.api.client()?;
eprintln!("Looking up the app...");
let app = self.ident.resolve(&client).await?;
if interactive {
let should_use = Confirm::new()
.with_prompt(&format!(
"Really delete the app '{}/{}'? (id: {})",
app.owner.global_name,
app.name,
app.id.inner()
))
.interact()?;
if !should_use {
eprintln!("App will not be deleted.");
return Ok(());
}
}
eprintln!(
"Deleting app {}/{} (id: {})...",
app.owner.global_name,
app.name,
app.id.inner(),
);
wasmer_api::backend::delete_app(&client, app.id.into_inner()).await?;
eprintln!("App '{}/{}' was deleted!", app.owner.global_name, app.name);
Ok(())
}
}
impl AsyncCliCommand for CmdAppDelete {
fn run_async(self) -> futures::future::BoxFuture<'static, Result<(), anyhow::Error>> {
Box::pin(self.run())
}
}