From e7fd4ae8b5aac082bca4fd5a7220687fb21e4d24 Mon Sep 17 00:00:00 2001 From: Aaron Allen Date: Mon, 13 Apr 2026 10:08:18 -0500 Subject: [PATCH] feat(cli): remove hard-coded unfinished filter from last command The last command now shows the most recent entry regardless of status. Use --unfinished to restore the old behavior. The error message when no entry matches now explains which filters are active. Closes #309 --- src/cli/commands/last.rs | 46 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/cli/commands/last.rs b/src/cli/commands/last.rs index 2fb21d6..31adad2 100644 --- a/src/cli/commands/last.rs +++ b/src/cli/commands/last.rs @@ -54,7 +54,24 @@ impl Command { let filtered = self.find_last_entry(ctx)?; if filtered.is_empty() { - ctx.status("No matching entry found"); + let mut filters = Vec::new(); + if let Some(section) = &self.filter.section { + filters.push(format!("section={section}")); + } + if self.filter.unfinished { + filters.push("unfinished".to_string()); + } + for tag in &self.filter.tag { + filters.push(format!("tag={tag}")); + } + if let Some(search) = &self.filter.search { + filters.push(format!("search={search}")); + } + if filters.is_empty() { + ctx.status("No matching entry found"); + } else { + ctx.status(format!("No matching entry found (filters: {})", filters.join(", "))); + } return Ok(()); } @@ -108,7 +125,6 @@ impl Command { options.count = Some(1); options.age = Some(Age::Newest); options.sort = Some(SortOrder::Desc); - options.unfinished = true; Ok(filter_entries(all_entries, &options)) } @@ -290,13 +306,31 @@ mod test { } #[test] - fn it_skips_done_entries() { - let mut ctx = sample_ctx_with_done_last(); + fn it_shows_finished_entries_by_default() { + let ctx = sample_ctx_with_done_last(); let cmd = default_cmd(); - let result = cmd.call(&mut ctx); + let entries = cmd.find_last_entry(&ctx).unwrap(); - assert!(result.is_ok()); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].title(), "Done task"); + } + + #[test] + fn it_skips_done_entries_with_unfinished_flag() { + let ctx = sample_ctx_with_done_last(); + let cmd = Command { + filter: FilterArgs { + unfinished: true, + ..FilterArgs::default() + }, + ..default_cmd() + }; + + let entries = cmd.find_last_entry(&ctx).unwrap(); + + assert_eq!(entries.len(), 1); + assert_eq!(entries[0].title(), "Active task"); } } } -- knotmirror 0.0.1