From 8a15ad89d7df16c9a82721bae1e9ba8d5ab02dd2 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 10 Dec 2018 18:23:29 +0100 Subject: Add config file --- src/errors.rs | 21 +++++++++++++++++++++ src/lib.rs | 7 +++++++ src/main.rs | 12 ++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/errors.rs b/src/errors.rs index be78bcf..9f570d2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,7 @@ +use std::io; use std::num::ParseIntError; use ical::parser; +use toml; #[derive(Debug)] pub enum EventError { @@ -20,3 +22,22 @@ impl From for EventError { EventError::IntError(err) } } + +#[derive(Debug)] +pub enum ConfigError { + IOError(io::Error), + ParseError(toml::de::Error), + MissingPath, +} + +impl From for ConfigError { + fn from(err: io::Error) -> ConfigError { + ConfigError::IOError(err) + } +} + +impl From for ConfigError { + fn from(err: toml::de::Error) -> ConfigError { + ConfigError::ParseError(err) + } +} diff --git a/src/lib.rs b/src/lib.rs index b82b190..3b0498c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,14 +2,21 @@ extern crate ical; extern crate chrono; extern crate chrono_tz; extern crate itertools; +extern crate dirs; +extern crate toml; + +#[macro_use] +extern crate serde_derive; mod date; mod event; mod periodic; mod calendar; +mod config; mod errors; pub use calendar::Calendar; pub use date::Date; pub use chrono::Duration; pub use event::Event; +pub use config::Config; diff --git a/src/main.rs b/src/main.rs index beca8d9..b7afdb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,19 +12,27 @@ use almanac::Calendar; use almanac::Date; use almanac::Duration; use almanac::Event; +use almanac::Config; fn main() { let mut args = env::args().skip(1); let period_arg = match args.next() { Some(arg) => arg, None => { - println!("Usage: almanac [day|week|month] ics [ics ...]"); + println!("Usage: almanac day|week|month [ical ...]"); return; } }; let (first, last) = period(&period_arg); - let calendars: Vec<_> = args.map(|arg| ics_calendar(&arg)).collect(); + let mut calendars: Vec<_> = args.map(|arg| ics_calendar(&arg)).collect(); + if calendars.is_empty() { + let conf = Config::parse().unwrap(); + for cal in &conf.cals { + calendars.push(ics_calendar(cal)) + } + } + let events = calendars .iter() .map(|c| c.iter()) -- cgit v1.2.3