mirror of
https://github.com/nikolassv/bartib
synced 2024-11-10 06:04:17 +00:00
feat: make project in report accept wildcards for filtering
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
This commit is contained in:
parent
4485d79316
commit
47b94f91cb
3 changed files with 16 additions and 3 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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!(
|
||||
|
|
Loading…
Reference in a new issue