-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogs.rs
More file actions
49 lines (38 loc) · 1.05 KB
/
logs.rs
File metadata and controls
49 lines (38 loc) · 1.05 KB
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
use anyhow::Result;
use clap::Args;
use hl::{git::infer_app_name, log::*};
use std::process::Stdio;
use tokio::process::Command;
#[derive(Args)]
pub struct LogsArgs {
/// Follow log output (stream logs)
#[arg(short, long)]
pub follow: bool,
/// Number of lines to show from the end of the logs
#[arg(short = 'n', long)]
pub tail: Option<String>,
}
pub async fn execute(args: LogsArgs) -> Result<()> {
let app = infer_app_name().await?;
let mut docker_args = vec!["logs".to_string()];
if args.follow {
docker_args.push("--follow".to_string());
}
if let Some(tail) = args.tail {
docker_args.push("--tail".to_string());
docker_args.push(tail);
}
docker_args.push(app.clone());
debug(&format!("executing: docker {}", docker_args.join(" ")));
let status = Command::new("docker")
.args(&docker_args)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.await?;
if !status.success() {
anyhow::bail!("docker logs failed with status: {}", status);
}
Ok(())
}