caltemps 0.2.1

A tool to query and report on your iCalendar data from vDirs.
Documentation
use caltemps::{CalTempsDateRange, Cli, Settings, get_matching_entry, read_vdir_cal};
use clap::Parser;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // BEGIN: args
    let cli = Cli::parse();
    let cfg = Settings::new(cli.config).unwrap();
    let date_range = CalTempsDateRange::new(cli.date_range.unwrap_or(cfg.default_date_range))?;
    let active_filter = cli.filter.unwrap_or(cfg.default_filter);
    // END: args

    match read_vdir_cal(Path::new(&cfg.vdir_path)) {
        Ok(cal) => {
            let mut x = 0;
            for c in cal
                .components
                .into_iter()
                .filter_map(|c| get_matching_entry(c, active_filter.clone(), &date_range))
            {
                if let Some(ds) = c.start {
                    if let Some(de) = c.end {
                        x += (de - ds).num_minutes();
                    }
                }
            }
            println!("Accounted {:.2}h", x as f64 / 60.0);
            Ok(())
        }
        Err(error) => {
            eprintln!("Error working on:\t'{}'", cfg.vdir_path);
            eprintln!("{}", error);
            Err(error)
        }
    }
}