wasmer-deploy-cli 0.1.29

CLI for Wasmer Deploy
Documentation
use dialoguer::Confirm;
use is_terminal::IsTerminal;

use crate::{cmd::AsyncCliCommand, ApiOpts};

use super::AppIdent;

/// Show an app.
#[derive(clap::Parser, Debug)]
pub struct CmdAppDelete {
    #[clap(flatten)]
    api: ApiOpts,

    #[clap(long)]
    non_interactive: bool,

    /// Identifier of the app.
    ///
    /// Eg:
    /// - name (assumes current user)
    /// - namespace/name
    ///
    /// NOTE: if not specified, the command will try to infer the app from an
    /// app.yaml file in the current directory.
    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())
    }
}