aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--src/config.rs8
-rw-r--r--src/main.rs10
3 files changed, 18 insertions, 3 deletions
diff --git a/README.md b/README.md
index 636abba..ece1536 100644
--- a/README.md
+++ b/README.md
@@ -28,4 +28,7 @@ The format is:
```
# a list of icals to be used if none is provided to the program
cals = ["/home/foo/mycal.ics", "/tmp/anothercal.ics"]
+
+# default period to display
+period = "day"
```
diff --git a/src/config.rs b/src/config.rs
index 7280aed..86ab51a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -10,9 +10,17 @@ const CONFIG_NAME: &str = "almanac.toml";
#[derive(Deserialize)]
pub struct Config {
pub cals: Vec<String>,
+ pub period: String,
}
impl Config {
+ pub fn new() -> Config {
+ Config {
+ cals: vec![],
+ period: "".to_string(),
+ }
+ }
+
pub fn parse() -> Result<Config, ConfigError> {
let config_path = match dirs::config_dir() {
Some(path) => path,
diff --git a/src/main.rs b/src/main.rs
index a65ace0..64fdf05 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,19 +15,23 @@ use almanac::Event;
use almanac::Config;
fn main() {
+ let conf = Config::parse().unwrap_or(Config::new());
let mut args = env::args().skip(1);
let period_arg = match args.next() {
Some(arg) => arg,
None => {
- println!("Usage: almanac day|week|month [ical ...]");
- return;
+ if conf.period.is_empty() {
+ println!("Usage: almanac day|week|month [ical ...]");
+ return;
+ } else {
+ conf.period
+ }
}
};
let (first, last) = period(&period_arg);
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))
}