wasmer_cli/commands/app/
delete.rs

1//! Delete an Edge app.
2
3use dialoguer::Confirm;
4use is_terminal::IsTerminal;
5
6use super::util::AppIdentOpts;
7use crate::{commands::AsyncCliCommand, config::WasmerEnv};
8
9/// Delete an existing Edge app
10#[derive(clap::Parser, Debug)]
11pub struct CmdAppDelete {
12    #[clap(flatten)]
13    env: WasmerEnv,
14
15    #[clap(long, default_value_t = !std::io::stdin().is_terminal())]
16    non_interactive: bool,
17
18    #[clap(flatten)]
19    ident: AppIdentOpts,
20}
21
22#[async_trait::async_trait]
23impl AsyncCliCommand for CmdAppDelete {
24    type Output = ();
25
26    async fn run_async(self) -> Result<(), anyhow::Error> {
27        let interactive = !self.non_interactive;
28        let client = self.env.client()?;
29
30        eprintln!("Looking up the app...");
31        let (_ident, app) = self.ident.load_app(&client).await?;
32
33        if interactive {
34            let theme = dialoguer::theme::ColorfulTheme::default();
35            let should_use = Confirm::with_theme(&theme)
36                .with_prompt(format!(
37                    "Really delete the app '{}/{}'? (id: {})",
38                    app.owner.global_name,
39                    app.name,
40                    app.id.inner()
41                ))
42                .interact()?;
43
44            if !should_use {
45                eprintln!("App will not be deleted.");
46                return Ok(());
47            }
48        }
49
50        eprintln!(
51            "Deleting app {}/{} (id: {})...",
52            app.owner.global_name,
53            app.name,
54            app.id.inner(),
55        );
56        wasmer_backend_api::query::delete_app(&client, app.id.into_inner()).await?;
57
58        eprintln!("App '{}/{}' was deleted!", app.owner.global_name, app.name);
59
60        Ok(())
61    }
62}