(177665) Add ls command

This commit is contained in:
2026-05-14 21:37:11 +02:00
parent 17a02b906e
commit fd216b056c
4 changed files with 343 additions and 10 deletions
+7
View File
@@ -44,4 +44,11 @@ pub enum Command {
#[arg(short, long)]
owner: Option<String>,
},
/// List tickets, optionally filtered by status
Ls {
/// Filter by status (backlog, committed, reviewing, done)
#[arg(long)]
status: Option<String>,
},
}
+113
View File
@@ -55,6 +55,115 @@ fn cmd_init(start: &Path) -> Result<()> {
Ok(())
}
fn parse_ticket_field(content: &str, field: &str) -> String {
let pattern = format!("**{}**", field);
content
.lines()
.find(|line| line.contains(&pattern))
.map(|line| {
line.split(':').nth(1).unwrap_or("").trim().trim_matches('_').trim()
})
.unwrap_or("_Not set_")
.to_string()
}
fn status_dirs() -> Vec<&'static str> {
vec!["backlog", "committed", "reviewing", "done"]
}
fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
if let Some(status) = status_filter {
let status_path = worklane_dir.join(status);
if !status_path.exists() {
return Err(anyhow!(
"Status '{}' not found. Valid statuses: backlog, committed, reviewing, done",
status
));
}
let entries: Vec<_> = fs::read_dir(&status_path)?
.filter_map(|e| e.ok())
.collect();
if entries.is_empty() {
println!("No tickets in '{}' status.", status);
return Ok(());
}
let mut items: Vec<_> = entries
.iter()
.filter_map(|e| {
let content = fs::read_to_string(e.path()).ok()?;
let title = content
.lines()
.find(|l| l.starts_with("# "))
.map(|l| l[2..].trim())
.unwrap_or("_No title_")
.to_string();
let owner = parse_ticket_field(&content, "Owner");
let due = parse_ticket_field(&content, "Due");
Some((title, owner, due))
})
.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);
}
} else {
// List all statuses with their ticket counts
let statuses = status_dirs();
println!("Tickets by status:\n");
for status in &statuses {
let status_path = worklane_dir.join(status);
if !status_path.exists() {
continue;
}
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
let count = entries.len();
let label = if count == 1 { "ticket" } else { "tickets" };
println!(" [{}] {} {}", status.to_uppercase(), count, label);
}
// Show all tickets grouped by status
for status in &statuses {
let status_path = worklane_dir.join(status);
if !status_path.exists() {
continue;
}
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
if entries.is_empty() {
continue;
}
let mut items: Vec<_> = entries
.iter()
.filter_map(|e| {
let content = fs::read_to_string(e.path()).ok()?;
let title = content
.lines()
.find(|l| l.starts_with("# "))
.map(|l| l[2..].trim())
.unwrap_or("_No title_")
.to_string();
let owner = parse_ticket_field(&content, "Owner");
let due = parse_ticket_field(&content, "Due");
Some((title, owner, due))
})
.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);
}
}
}
Ok(())
}
fn cmd_add(
title: &str,
description: &Option<String>,
@@ -162,5 +271,9 @@ fn main() -> Result<()> {
} => cmd_add(
&title, &description, &acceptance, &plan, &tags, &due, &owner, &start,
),
Command::Ls { status } => {
let worklane_dir = find_worklane_dir(&start)?;
cmd_ls(&status, &worklane_dir)
}
}
}