Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make project in report accept wildcards for filtering #45

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "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
Expand Down
11 changes: 8 additions & 3 deletions src/data/getter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chrono::NaiveDate;
use std::collections::HashSet;
use wildmatch::WildMatch;

use crate::data::activity;
use crate::data::activity::Activity;
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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!(
Expand All @@ -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!(
Expand Down
Loading