wasmer-deploy-client-cli 0.1.1

CLI client for Wasmer Deploy
Documentation
use crate::{cmd::AsyncCliCommand, ApiOpts, ListFormatOpts};

#[derive(clap::Parser, Debug)]
pub struct CmdAppList {
    #[clap(flatten)]
    fmt: ListFormatOpts,
    #[clap(flatten)]
    api: ApiOpts,

    /// Get apps in a specific namespace.
    ///
    /// Will fetch the apps owned by the current user otherwise.
    #[clap(short = 'n', long)]
    namespace: Option<String>,

    /// Get all apps that are accessible by the current user, including apps
    /// directly owned by the user and apps in namespaces the user can access.
    #[clap(short = 'a', long)]
    all: bool,
}

impl CmdAppList {
    async fn run(self) -> Result<(), anyhow::Error> {
        let client = self.api.client()?;

        let apps = if let Some(ns) = self.namespace {
            wasmer_api::backend::namespace_apps(&client, &ns).await?
        } else if self.all {
            wasmer_api::backend::user_accessible_apps(&client).await?
        } else {
            wasmer_api::backend::user_apps(&client).await?
        };

        println!("{}", self.fmt.format.render(&apps));

        Ok(())
    }
}

impl AsyncCliCommand for CmdAppList {
    fn run_async(self) -> futures::future::BoxFuture<'static, Result<(), anyhow::Error>> {
        Box::pin(self.run())
    }
}