compact_calendar_cli/
lib.rs

1pub mod config;
2pub mod formatting;
3pub mod models;
4pub mod rendering;
5
6use config::CalendarConfig;
7use models::{Calendar, ColorMode, PastDateDisplay, WeekStart, WeekendDisplay};
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(
35    year: i32,
36    week_start: WeekStart,
37    weekend_display: WeekendDisplay,
38    color_mode: ColorMode,
39    past_date_display: PastDateDisplay,
40    config: CalendarConfig,
41) -> Calendar {
42    let details = config.parse_dates_for_year(year);
43    let ranges = config.parse_ranges_for_year(year);
44    Calendar::new(
45        year,
46        week_start,
47        weekend_display,
48        color_mode,
49        past_date_display,
50        details,
51        ranges,
52    )
53}