wasmer_cli/commands/app/database/
list.rs

1//! List volumes tied to an edge app.
2
3use super::super::util::AppIdentOpts;
4use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts};
5
6/// List the volumes of an app.
7#[derive(clap::Parser, Debug)]
8pub struct CmdAppDatabaseList {
9    #[clap(flatten)]
10    fmt: ListFormatOpts,
11
12    #[clap(flatten)]
13    env: WasmerEnv,
14
15    #[clap(flatten)]
16    ident: AppIdentOpts,
17
18    #[clap(long, help = "Include password in the output")]
19    pub with_password: bool,
20}
21
22#[async_trait::async_trait]
23impl AsyncCliCommand for CmdAppDatabaseList {
24    type Output = ();
25
26    async fn run_async(self) -> Result<(), anyhow::Error> {
27        let client = self.env.client()?;
28
29        let (_ident, app) = self.ident.load_app(&client).await?;
30        let mut dbs = wasmer_backend_api::query::get_app_databases(
31            &client,
32            &app.owner.global_name,
33            &app.name,
34        )
35        .await?;
36
37        if !self.with_password {
38            dbs.iter_mut().for_each(|db| {
39                db.password = None;
40            });
41        }
42
43        if dbs.is_empty() {
44            eprintln!("App {} has no databases!", app.name);
45        } else {
46            println!("{}", self.fmt.format.render(dbs.as_slice()));
47        }
48
49        Ok(())
50    }
51}