compact_calendar_cli/
lib.rs

1pub mod config;
2pub mod formatting;
3pub mod models;
4pub mod rendering;
5
6use config::CalendarConfig;
7use models::{Calendar, CalendarOptions};
8use std::fs;
9use std::path::PathBuf;
10
11pub fn load_config(config_path: &PathBuf) -> CalendarConfig {
12    if !config_path.exists() {
13        eprintln!(
14            "Config file not found at {:?}, using empty configuration",
15            config_path
16        );
17        return CalendarConfig {
18            dates: Default::default(),
19            ranges: Default::default(),
20        };
21    }
22
23    let contents = fs::read_to_string(config_path).unwrap_or_else(|e| {
24        eprintln!("Failed to read config file {:?}: {}", config_path, e);
25        std::process::exit(1);
26    });
27
28    toml::from_str(&contents).unwrap_or_else(|e| {
29        eprintln!("Failed to parse TOML config: {}", e);
30        std::process::exit(1);
31    })
32}
33
34pub fn build_calendar(year: i32, options: CalendarOptions, config: CalendarConfig) -> Calendar {
35    let details = config.parse_dates_for_year(year);
36    let ranges = config.parse_ranges_for_year(year);
37    Calendar::new(year, options, details, ranges)
38}