wasmer_cli/commands/app/
purge_cache.rs1use anyhow::Context;
4
5use super::util::AppIdentOpts;
6use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts};
7
8#[derive(clap::Parser, Debug)]
15pub struct CmdAppPurgeCache {
16    #[clap(flatten)]
17    pub env: WasmerEnv,
18
19    #[clap(flatten)]
20    pub fmt: ItemFormatOpts,
21
22    #[clap(flatten)]
23    pub ident: AppIdentOpts,
24}
25
26#[async_trait::async_trait]
27impl AsyncCliCommand for CmdAppPurgeCache {
28    type Output = ();
29
30    async fn run_async(self) -> Result<(), anyhow::Error> {
31        let client = self.env.client()?;
32        let (_ident, app) = self.ident.load_app(&client).await?;
33
34        let version_id = app
35            .active_version
36            .as_ref()
37            .context("Could not purge cache: app has no active version!")?
38            .id
39            .clone();
40
41        let name = format!("{} ({})", app.name, app.owner.global_name);
42
43        println!(
44            "Purging caches for {}, app version {}...",
45            name,
46            version_id.inner()
47        );
48
49        let vars = wasmer_backend_api::types::PurgeCacheForAppVersionVars { id: version_id };
50        wasmer_backend_api::query::purge_cache_for_app_version(&client, vars).await?;
51
52        println!("🚽 swirl! All caches have been purged!");
53
54        Ok(())
55    }
56}