From e37ff3447ec38823361c71910455bec5ad74035c Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Sun, 28 Dec 2025 15:16:20 +0000 Subject: [PATCH] cli: add timestamp to output With the Run storing the timestamp, it can be added to the CLI output as well. When pretty printing the timestamp, `chrono` is used to have a date-time format. --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/display.rs | 13 +++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1326003..ec13c01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,6 +276,15 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "num-traits", +] + [[package]] name = "cipher" version = "0.4.4" @@ -1364,6 +1373,7 @@ dependencies = [ name = "radicle-job" version = "0.4.0" dependencies = [ + "chrono", "clap", "indexmap", "nonempty 0.11.0", diff --git a/Cargo.toml b/Cargo.toml index 3cbab53..6d635a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ edition = "2021" rust-version = "1.84.0" [dependencies] +chrono = { version = "0.4", default-features = false } clap = { version = "4.5.41", features = ["derive", "wrap_help"] } indexmap = { version = "2.7.1", features = ["serde"] } nonempty = "0.11.0" diff --git a/src/display.rs b/src/display.rs index 985d92a..67f512e 100644 --- a/src/display.rs +++ b/src/display.rs @@ -3,7 +3,8 @@ //! These can be used in tools that wish to display data, such as the `rad-job` //! CLI tool. -use radicle::{git::Oid, node::NodeId}; +use chrono::Utc; +use radicle::{cob, git::Oid, node::NodeId}; use serde::Serialize; use url::Url; use uuid::Uuid; @@ -78,6 +79,7 @@ impl Job { run_id: *run_id, status: *run.status(), log: run.log().clone(), + timestamp: *run.timestamp(), }) .collect(); runs.sort_by_cached_key(|run| run.run_id); @@ -109,7 +111,13 @@ impl Job { for run in self.runs.iter() { line(&mut s, format!(" node {}", run.node_id)); for run2 in run.runs.iter() { - line(&mut s, format!(" run {} {:?}", run2.run_id, run2.status)); + let date = + chrono::DateTime::::from_timestamp_secs(run2.timestamp.as_secs() as i64) + .expect("run timestamp is out of range"); + line( + &mut s, + format!(" run {} {:?} [{}]", run2.run_id, run2.status, date), + ); line(&mut s, format!(" log {}", run2.log)); } } @@ -129,4 +137,5 @@ struct Run { run_id: Uuid, status: Status, log: Url, + timestamp: cob::Timestamp, }