From 47b94f91cb112592d6607127f093e9c8c55d33e0 Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:45:43 +0100 Subject: [PATCH 1/3] feat: make project in report accept wildcards for filtering Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/data/getter.rs | 11 ++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fa0d28..dd3e16d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,7 @@ dependencies = [ "term_size", "textwrap 0.16.0", "thiserror", + "wildmatch", ] [[package]] @@ -377,6 +378,12 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wildmatch" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "495ec47bf3c1345005f40724f0269362c8556cbc43aed0526ed44cae1d35fceb" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index dafb680..97d5ed7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ anyhow = "1.0.0" nu-ansi-term = "0.46.0" term_size = "0.3.0" textwrap = "0.16.0" +wildmatch = "2.3.0" diff --git a/src/data/getter.rs b/src/data/getter.rs index dcf237f..b696bf8 100644 --- a/src/data/getter.rs +++ b/src/data/getter.rs @@ -1,5 +1,6 @@ use chrono::NaiveDate; use std::collections::HashSet; +use wildmatch::WildMatch; use crate::data::activity; use crate::data::activity::Activity; @@ -94,7 +95,11 @@ pub fn filter_activities<'a>( .filter(move |activity| { activity.start.date() >= from_date && activity.start.date() <= to_date }) - .filter(move |activity| filter.project.map_or(true, |p| activity.project == *p)) + .filter(move |activity| { + filter + .project + .map_or(true, |p| WildMatch::new(p).matches(&activity.project)) + }) .collect() } @@ -132,7 +137,7 @@ mod tests { assert_eq!(descriptions_and_projects.len(), 2); assert_eq!( - *descriptions_and_projects.get(0).unwrap(), + *descriptions_and_projects.first().unwrap(), (&"d1".to_string(), &"p1".to_string()) ); assert_eq!( @@ -153,7 +158,7 @@ mod tests { assert_eq!(descriptions_and_projects.len(), 2); assert_eq!( - *descriptions_and_projects.get(0).unwrap(), + *descriptions_and_projects.first().unwrap(), (&"d1".to_string(), &"p2".to_string()) ); assert_eq!( From afdf43399a0482326d2e6c0a4491360bba71706a Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Sat, 27 Jan 2024 12:52:54 +0100 Subject: [PATCH 2/3] docs: add remark on wildcard operator in report --projects filter --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5a2174d..fc5440a 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,7 @@ bartib report --last_week # create a report for the last week bartib report --date 2021-09-03 # create a report for a given day bartib report --from 2021-09-01 --to 2021-09-05 # create a report for a given time range bartib report --project "The most exciting project" # create a report for a given project +bartib report --project "maintenance::*" # you can use wildcards as well to filter for projects, like this you can implement scopes bartib report --round 15m # rounds the start and end time to the nearest duration. Durations can be in minutes or hours. E.g. 15m or 4h bartib list # list all activities grouped by day From db1b63e7cc0be6fcac48af7d6d83bc8a8d904753 Mon Sep 17 00:00:00 2001 From: Nikolas Schmidt-Voigt Date: Wed, 7 Feb 2024 09:03:10 +0100 Subject: [PATCH 3/3] docs: changed documentation for wildcards --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc5440a..0dd481d 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ bartib report --last_week # create a report for the last week bartib report --date 2021-09-03 # create a report for a given day bartib report --from 2021-09-01 --to 2021-09-05 # create a report for a given time range bartib report --project "The most exciting project" # create a report for a given project -bartib report --project "maintenance::*" # you can use wildcards as well to filter for projects, like this you can implement scopes +bartib report --project "Maint?nance *" # use '?' and '*' as wildcards in project names bartib report --round 15m # rounds the start and end time to the nearest duration. Durations can be in minutes or hours. E.g. 15m or 4h bartib list # list all activities grouped by day