wasmer_cli/commands/app/version/
activate.rs

1use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts};
2
3/// Switch the active version of an app. (rollback / rollforward)
4#[derive(clap::Parser, Debug)]
5pub struct CmdAppVersionActivate {
6    #[clap(flatten)]
7    pub env: WasmerEnv,
8
9    #[clap(flatten)]
10    pub fmt: ItemFormatOpts,
11
12    /// App version ID to activate.
13    ///
14    /// This must be the unique version ID, not the version name!
15    /// Eg: dav_xYzaB1aaaaax
16    pub version: String,
17}
18
19#[async_trait::async_trait]
20impl AsyncCliCommand for CmdAppVersionActivate {
21    type Output = ();
22
23    async fn run_async(self) -> Result<(), anyhow::Error> {
24        let client = self.env.client()?;
25
26        let app = wasmer_backend_api::query::app_version_activate(&client, self.version).await?;
27
28        let Some(version) = &app.active_version else {
29            anyhow::bail!("Failed to activate version: backend did not update version!");
30        };
31
32        eprintln!(
33            "Changed active version of app '{}/{}' from '{}' to '{}' (id: {})",
34            app.owner.global_name,
35            app.name,
36            version.version,
37            version.version,
38            version.id.inner(),
39        );
40
41        Ok(())
42    }
43}