diff --git a/src/commands/logs.rs b/src/commands/logs.rs index 74881ade5..182d9438b 100644 --- a/src/commands/logs.rs +++ b/src/commands/logs.rs @@ -10,7 +10,7 @@ use super::{ *, }; -/// View the most-recent deploy's logs +/// View a deploy's logs #[derive(Parser)] pub struct Args { /// Service to view logs from (defaults to linked service) @@ -28,6 +28,9 @@ pub struct Args { /// Show build logs #[clap(short, long, group = "log_type")] build: bool, + + /// Deployment ID to pull logs from. Omit to pull from latest deloy + deployment_id: Option, } pub async fn command(args: Args, json: bool) -> Result<()> { @@ -82,11 +85,23 @@ pub async fn command(args: Args, json: bool) -> Result<()> { (deployment.node.status == DeploymentStatus::SUCCESS).then_some(deployment.node) }) .collect(); - deployments.sort_by(|a, b| b.created_at.cmp(&a.created_at)); - let latest_deployment = deployments.first().context("No deployments found")?; - if (args.build || latest_deployment.status == DeploymentStatus::FAILED) && !args.deployment { - stream_build_logs(latest_deployment.id.clone(), |log| { + let deployment; + if let Some(deployment_id) = args.deployment_id { + deployment = deployments + .iter() + .find(|deployment| { + deployment.id == deployment_id + }) + .context("Deployment id does not exist")?; + } else { + // get the latest deloyment + deployments.sort_by(|a, b| b.created_at.cmp(&a.created_at)); + deployment = deployments.first().context("No deployments found")?; + }; + + if (args.build || deployment.status == DeploymentStatus::FAILED) && !args.deployment { + stream_build_logs(deployment.id.clone(), |log| { if json { println!("{}", serde_json::to_string(&log).unwrap()); } else { @@ -95,7 +110,7 @@ pub async fn command(args: Args, json: bool) -> Result<()> { }) .await?; } else { - stream_deploy_logs(latest_deployment.id.clone(), |log| { + stream_deploy_logs(deployment.id.clone(), |log| { if json { println!("{}", serde_json::to_string(&log).unwrap()); } else {