1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use anyhow::Context;

use crate::{
    commands::{app::util::AppIdentOpts, AsyncCliCommand},
    config::WasmerEnv,
    opts::ItemFormatOpts,
    utils::render::ItemFormat,
};

/// Show information for a specific app version.
#[derive(clap::Parser, Debug)]
pub struct CmdAppVersionGet {
    #[clap(flatten)]
    pub env: WasmerEnv,

    #[clap(flatten)]
    pub fmt: ItemFormatOpts,

    /// *Name* of the version - NOT the unique version id!
    #[clap(long)]
    pub name: String,

    #[clap(flatten)]
    #[allow(missing_docs)]
    pub ident: AppIdentOpts,
}

#[async_trait::async_trait]
impl AsyncCliCommand for CmdAppVersionGet {
    type Output = ();

    async fn run_async(self) -> Result<(), anyhow::Error> {
        let client = self.env.client()?;
        let (_ident, app) = self.ident.load_app(&client).await?;

        let version = wasmer_backend_api::query::get_app_version(
            &client,
            app.owner.global_name,
            app.name,
            self.name.clone(),
        )
        .await?
        .with_context(|| format!("Could not find app version '{}'", self.name))?;

        println!(
            "{}",
            self.fmt.get_with_default(ItemFormat::Yaml).render(&version)
        );

        Ok(())
    }
}