(dca0b61) Add priority as a ticket field
Priority lived in tags, as p1 to p3, which ls could neither sort nor filter on, nothing validated, and a typo like P1 passed silently. ls sorted by title only, so a backlog of any size gave no ordering signal. Levels are 1 to 5 with 1 most urgent, matching what the tags meant. Omitting the flag leaves the field _Not set_, like Due and Owner: there is no implicit middle level, because a priority nobody chose is worse than none. clap rejects anything outside the range before a ticket is written. Priority parses to three states rather than two. A stored value outside the range is Invalid, kept distinct from Unset, so a typo cannot read as "no priority": it shows as ? and sorts just ahead of the unset tail. ls sorts on priority and falls back to the old title sort, and --priority filters, composing with the status filter in both the grouped and the filtered listing. TicketItem becomes a struct, since a sixth tuple field was past reading. Migrated the 31 tickets already carrying p1 to p3 tags: the level moves to the field and the tag is dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b7781a830c
commit
ddbd45e332
+26
-5
@@ -29,7 +29,11 @@ pub fn cmd_init(start: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
|
||||
pub fn cmd_ls(
|
||||
status_filter: &Option<String>,
|
||||
priority_filter: Option<u8>,
|
||||
worklane_dir: &Path,
|
||||
) -> Result<()> {
|
||||
if let Some(status) = status_filter {
|
||||
let status_path = worklane_dir.join(status);
|
||||
if !status_path.exists() {
|
||||
@@ -39,7 +43,7 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
));
|
||||
}
|
||||
|
||||
let items = collect_ticket_items(&status_path)?;
|
||||
let items = filter_by_priority(collect_ticket_items(&status_path)?, priority_filter);
|
||||
|
||||
if items.is_empty() {
|
||||
println!("No tickets in '{}' status.", status);
|
||||
@@ -57,8 +61,8 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
if !status_path.exists() {
|
||||
continue;
|
||||
}
|
||||
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
|
||||
let count = entries.len();
|
||||
let items = filter_by_priority(collect_ticket_items(&status_path)?, priority_filter);
|
||||
let count = items.len();
|
||||
let label = if count == 1 { "ticket" } else { "tickets" };
|
||||
println!(" [{}] {} {}", status.to_uppercase(), count, label);
|
||||
}
|
||||
@@ -73,7 +77,7 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
continue;
|
||||
}
|
||||
let items = match collect_ticket_items(&status_path) {
|
||||
Ok(items) => items,
|
||||
Ok(items) => filter_by_priority(items, priority_filter),
|
||||
Err(_) => continue,
|
||||
};
|
||||
if items.is_empty() {
|
||||
@@ -88,6 +92,17 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Keep only the tickets at `level`, or everything when no level was asked for.
|
||||
fn filter_by_priority(items: Vec<TicketItem>, level: Option<u8>) -> Vec<TicketItem> {
|
||||
match level {
|
||||
Some(level) => items
|
||||
.into_iter()
|
||||
.filter(|item| item.priority == Priority::Level(level))
|
||||
.collect(),
|
||||
None => items,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cmd_add(
|
||||
title: &str,
|
||||
description: &[String],
|
||||
@@ -96,6 +111,7 @@ pub fn cmd_add(
|
||||
tags: &[String],
|
||||
due: &Option<String>,
|
||||
owner: &Option<String>,
|
||||
priority: Option<u8>,
|
||||
start: &Path,
|
||||
) -> Result<()> {
|
||||
let owner = match owner {
|
||||
@@ -141,6 +157,7 @@ pub fn cmd_add(
|
||||
## Metadata\n\
|
||||
\n\
|
||||
- **ID**: {}\n\
|
||||
- **Priority**: {}\n\
|
||||
- **Tags**: {}\n\
|
||||
- **Due**: {}\n\
|
||||
- **Owner**: {}\n\
|
||||
@@ -168,6 +185,10 @@ pub fn cmd_add(
|
||||
.join("\n")
|
||||
},
|
||||
id,
|
||||
match priority {
|
||||
Some(level) => level.to_string(),
|
||||
None => "_Not set_".to_string(),
|
||||
},
|
||||
if tags.is_empty() {
|
||||
"_None_".to_string()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user