use anyhow::Context;
use crate::{cmd::AsyncCliCommand, ApiOpts, ItemFormatOpts};
#[derive(clap::Parser, Debug)]
pub struct CmdAppGet {
#[clap(flatten)]
api: ApiOpts,
#[clap(flatten)]
fmt: ItemFormatOpts,
ident: String,
}
impl CmdAppGet {
async fn run(self) -> Result<(), anyhow::Error> {
let client = self.api.client()?;
let (owner, name) = if let Some((namespace, name)) = self.ident.split_once('/') {
(namespace.to_string(), name.to_string())
} else {
let user = wasmer_api::backend::current_user(&client).await?;
(user.username, self.ident.clone())
};
let app = wasmer_api::backend::get_app(&client, owner.clone(), name.clone())
.await?
.context("app not found")?;
println!("{}", self.fmt.format.render(&app));
Ok(())
}
}
impl AsyncCliCommand for CmdAppGet {
fn run_async(self) -> futures::future::BoxFuture<'static, Result<(), anyhow::Error>> {
Box::pin(self.run())
}
}