aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/errors.rs21
-rw-r--r--src/lib.rs7
-rw-r--r--src/main.rs12
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)
+ }
+}
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())