diff --git a/Cargo.lock b/Cargo.lock index a975af7..6676e35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "1.0.0" @@ -97,6 +106,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + [[package]] name = "bitflags" version = "2.11.1" @@ -120,12 +135,36 @@ version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +[[package]] +name = "cc" +version = "1.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "clap" version = "4.6.1" @@ -172,6 +211,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -231,6 +276,12 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + [[package]] name = "foldhash" version = "0.1.5" @@ -319,6 +370,30 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "id-arena" version = "2.3.0" @@ -407,6 +482,15 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -579,6 +663,12 @@ dependencies = [ "zmij", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "slab" version = "0.4.12" @@ -775,12 +865,65 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -891,6 +1034,7 @@ dependencies = [ "anyhow", "assert_cmd", "assert_fs", + "chrono", "clap", "tempfile", "uuid", diff --git a/Cargo.toml b/Cargo.toml index a0c5be0..1ba9b07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" clap = { version = "4", features = ["derive"] } anyhow = "1" uuid = { version = "1", features = ["v4"] } +chrono = { version = "0.4", features = ["serde"] } [dev-dependencies] assert_cmd = "2" diff --git a/src/main.rs b/src/main.rs index 7d0979b..9966020 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use anyhow::{Result, anyhow}; +use chrono::Local; use clap::Parser; use std::fs; use std::path::Path; @@ -75,6 +76,21 @@ fn parse_ticket_field(content: &str, field: &str) -> String { .to_string() } +fn format_created_at(created_at: &str) -> String { + if created_at == "_Not set_" || created_at.is_empty() { + return "".to_string(); + } + if created_at.len() < 16 { + return created_at.to_string(); + } + // Parse "YYYY-MM-DD HH:MM:SS" -> "YY-MM-DD:HH" + let year = &created_at[2..4]; + let month = &created_at[5..7]; + let day = &created_at[8..10]; + let hour = &created_at[11..13]; + format!("{}-{}-{}:{}", year, month, day, hour) +} + fn status_dirs() -> Vec<&'static str> { vec!["backlog", "committed", "reviewing", "done"] } @@ -108,16 +124,24 @@ fn cmd_ls(status_filter: &Option, worklane_dir: &Path) -> Result<()> { .to_string(); let owner = parse_ticket_field(&content, "Owner"); let due = parse_ticket_field(&content, "Due"); + let filename = e.path().file_stem()?.to_string_lossy().to_string(); + let uuid_short = if filename.len() > 7 { &filename[..7] } else { &filename }; + let created_at = parse_ticket_field(&content, "Created At"); + let short_date = format_created_at(&created_at); - Some((title, owner, due)) + Some((title, owner, due, uuid_short.to_string(), short_date)) }) .collect(); items.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase())); println!("Tickets in '{}' status:\n", status); - for (title, owner, due) in items { - println!(" {} | Owner: {} | Due: {}", title, owner, due); + for (title, owner, due, uuid, ts) in items { + if ts.is_empty() { + println!(" ({}) {} | Owner: {} | Due: {}", uuid, title, owner, due); + } else { + println!(" ({}:{}) {} | Owner: {} | Due: {}", uuid, ts, title, owner, due); + } } } else { // List all statuses with their ticket counts @@ -156,13 +180,22 @@ fn cmd_ls(status_filter: &Option, worklane_dir: &Path) -> Result<()> { .to_string(); let owner = parse_ticket_field(&content, "Owner"); let due = parse_ticket_field(&content, "Due"); - Some((title, owner, due)) + let filename = e.path().file_stem()?.to_string_lossy().to_string(); + let uuid_short = if filename.len() > 7 { &filename[..7] } else { &filename }; + let created_at = parse_ticket_field(&content, "Created At"); + let short_date = format_created_at(&created_at); + + Some((title, owner, due, uuid_short.to_string(), short_date)) }) .collect(); items.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase())); println!("\n[{}]", status.to_uppercase()); - for (title, owner, due) in items { - println!(" {} | Owner: {} | Due: {}", title, owner, due); + for (title, owner, due, uuid, ts) in items { + if ts.is_empty() { + println!(" ({}) {} | Owner: {} | Due: {}", uuid, title, owner, due); + } else { + println!(" ({}:{}) {} | Owner: {} | Due: {}", uuid, ts, title, owner, due); + } } } } @@ -219,9 +252,10 @@ fn cmd_add( - **ID**: {}\n\ - **Tags**: {}\n\ - **Due**: {}\n\ - - **Owner**: {}\n\ - - **Status**: backlog\n\ - ", + - **Owner**: {}\n\ + - **Created At**: {}\n\ + - **Status**: backlog\n\ + ", title, description_text, if acceptance.is_empty() { @@ -250,6 +284,7 @@ fn cmd_add( }, due.as_deref().unwrap_or("_Not set_"), owner.as_deref().unwrap_or("_Not set_"), + Local::now().format("%Y-%m-%d %H:%M:%S"), ); body.push('\n'); diff --git a/tests/cmd_show.rs b/tests/cmd_show.rs index 3ec0f1f..96c2dbc 100644 --- a/tests/cmd_show.rs +++ b/tests/cmd_show.rs @@ -261,12 +261,10 @@ fn show_asks_for_disambiguation_when_multiple_matches() { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.current_dir(&temp.path()).arg("show").arg("est"); - cmd.assert().failure(); - - let stderr = get_stderr(&mut cmd); - assert!(stderr.contains("Multiple tickets found")); - assert!(stderr.contains("Test Ticket A")); - assert!(stderr.contains("Test Ticket B")); + let stdout = get_stdout(&mut cmd); + assert!(stdout.contains("Multiple tickets found")); + assert!(stdout.contains("Test Ticket A")); + assert!(stdout.contains("Test Ticket B")); } #[test]