Skip to content

Commit

Permalink
Add deloyment id to logs (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadsw authored Sep 26, 2023
1 parent 1f7c000 commit 2952df1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/commands/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<String>,
}

pub async fn command(args: Args, json: bool) -> Result<()> {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 2952df1

Please sign in to comment.