From 2952df1fe2c840c76cc935dfad4a21ac76724a10 Mon Sep 17 00:00:00 2001 From: Sharad S <16229739+sharadsw@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:47:43 -0400 Subject: [PATCH] Add deloyment id to logs (#429) --- src/commands/logs.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) 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 {