mirror of
https://github.com/nikolassv/bartib
synced 2024-11-10 14:14:12 +00:00
Merge pull request #45 from simonsan/feat/report-wildcard
feat: make project in report accept wildcards for filtering
This commit is contained in:
commit
8798bce480
4 changed files with 17 additions and 3 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -60,6 +60,7 @@ dependencies = [
|
||||||
"term_size",
|
"term_size",
|
||||||
"textwrap 0.16.0",
|
"textwrap 0.16.0",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"wildmatch",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -377,6 +378,12 @@ version = "0.2.87"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
|
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wildmatch"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "495ec47bf3c1345005f40724f0269362c8556cbc43aed0526ed44cae1d35fceb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -19,3 +19,4 @@ anyhow = "1.0.0"
|
||||||
nu-ansi-term = "0.46.0"
|
nu-ansi-term = "0.46.0"
|
||||||
term_size = "0.3.0"
|
term_size = "0.3.0"
|
||||||
textwrap = "0.16.0"
|
textwrap = "0.16.0"
|
||||||
|
wildmatch = "2.3.0"
|
||||||
|
|
|
@ -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 --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 --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 "The most exciting project" # create a report for a given project
|
||||||
|
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 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
|
bartib list # list all activities grouped by day
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use wildmatch::WildMatch;
|
||||||
|
|
||||||
use crate::data::activity;
|
use crate::data::activity;
|
||||||
use crate::data::activity::Activity;
|
use crate::data::activity::Activity;
|
||||||
|
@ -94,7 +95,11 @@ pub fn filter_activities<'a>(
|
||||||
.filter(move |activity| {
|
.filter(move |activity| {
|
||||||
activity.start.date() >= from_date && activity.start.date() <= to_date
|
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()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +137,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(descriptions_and_projects.len(), 2);
|
assert_eq!(descriptions_and_projects.len(), 2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*descriptions_and_projects.get(0).unwrap(),
|
*descriptions_and_projects.first().unwrap(),
|
||||||
(&"d1".to_string(), &"p1".to_string())
|
(&"d1".to_string(), &"p1".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -153,7 +158,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(descriptions_and_projects.len(), 2);
|
assert_eq!(descriptions_and_projects.len(), 2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*descriptions_and_projects.get(0).unwrap(),
|
*descriptions_and_projects.first().unwrap(),
|
||||||
(&"d1".to_string(), &"p2".to_string())
|
(&"d1".to_string(), &"p2".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue