wasmer_cli/commands/app/deployments/
logs.rs1use std::io::Write;
4
5use anyhow::Context;
6use futures::stream::TryStreamExt;
7
8use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts};
9
10#[derive(clap::Parser, Debug)]
12pub struct CmdAppDeploymentLogs {
13 #[clap(flatten)]
14 fmt: ItemFormatOpts,
15
16 #[clap(flatten)]
17 env: WasmerEnv,
18
19 id: String,
21}
22
23#[async_trait::async_trait]
24impl AsyncCliCommand for CmdAppDeploymentLogs {
25 type Output = ();
26
27 async fn run_async(mut self) -> Result<(), anyhow::Error> {
28 let client = self.env.client()?;
29 let item = wasmer_backend_api::query::app_deployment(&client, self.id).await?;
30
31 let url = item
32 .log_url
33 .context("This deployment does not have logs available")?;
34
35 let mut writer = std::io::BufWriter::new(std::io::stdout());
36
37 let mut stream = reqwest::Client::new()
38 .get(url)
39 .send()
40 .await?
41 .error_for_status()?
42 .bytes_stream();
43
44 while let Some(chunk) = stream.try_next().await? {
45 writer.write_all(&chunk)?;
46 writer.flush()?;
47 }
48
49 Ok(())
50 }
51}