diff options
author | Ruben Pollan | 2018-12-10 18:23:29 +0100 |
---|---|---|
committer | Ruben Pollan | 2018-12-10 18:23:29 +0100 |
commit | 8a15ad89d7df16c9a82721bae1e9ba8d5ab02dd2 (patch) | |
tree | f0227e4b94d125f7237952c0aae6355bf05285f8 /src | |
parent | dc2d46735deaa2a8ba78702d5dd033f309fcfb0c (diff) |
Add config file
Diffstat (limited to 'src')
-rw-r--r-- | src/errors.rs | 21 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 12 |
3 files changed, 38 insertions, 2 deletions
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<ParseIntError> for EventError { EventError::IntError(err) } } + +#[derive(Debug)] +pub enum ConfigError { + IOError(io::Error), + ParseError(toml::de::Error), + MissingPath, +} + +impl From<io::Error> for ConfigError { + fn from(err: io::Error) -> ConfigError { + ConfigError::IOError(err) + } +} + +impl From<toml::de::Error> for ConfigError { + fn from(err: toml::de::Error) -> ConfigError { + ConfigError::ParseError(err) + } +} @@ -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()) |