tsk_rs/
project.rs

1use std::collections::HashMap;
2
3use color_eyre::eyre::{Context, Result};
4
5use crate::{settings::Settings, task::list_tasks};
6
7/// scan all active and done tasks to find projects in use
8pub fn scan_projects(settings: &Settings) -> Result<HashMap<String, usize>> {
9    let tasks = list_tasks(&None, &true, settings)
10        .with_context(|| "while scanning through all tasks")?;
11
12    let mut collected_projects: HashMap<String, usize> = HashMap::new();
13
14    for task in tasks {
15        if let Some(project) = task.project {
16                *collected_projects.entry(project).or_insert(0) += 1;
17        }
18    }
19
20    Ok(collected_projects)
21}
22
23// eof