feat: make project in report accept wildcards for filtering

Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
This commit is contained in:
simonsan 2024-01-27 11:45:43 +01:00
parent 4485d79316
commit 47b94f91cb
No known key found for this signature in database
GPG key ID: E11D13668EC3B71B
3 changed files with 16 additions and 3 deletions

7
Cargo.lock generated
View file

@ -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"

View file

@ -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"

View file

@ -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!(