tsk_rs/
tag.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 tags in use
8pub fn scan_tags(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_tags: HashMap<String, usize> = HashMap::new();
13
14    for task in tasks {
15        if let Some(tags) = task.tags {
16            for tag in tags {
17                *collected_tags.entry(tag).or_insert(0) += 1;
18            }
19        }
20    }
21
22    Ok(collected_tags)
23}
24
25// eof