From 182933226efefc1b9e8c3f8b86f1f40d0a485539 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 17 Aug 2022 14:38:31 +0200 Subject: [PATCH] ask for path, support extension --- src/ics.rs | 7 ++++++- src/main.rs | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ics.rs b/src/ics.rs index c1b44c8..9d637fc 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -57,7 +57,12 @@ pub fn export(courses: Vec, filename: &str) { calendar.add_event(event); } - calendar.save_file(filename).unwrap(); + calendar + .save_file(match filename.to_string() { + x if x.ends_with(".ics") => x, + x => format!("{}.ics", x), + }) + .unwrap(); } /// Transform the datetime from chrono to the ICS format diff --git a/src/main.rs b/src/main.rs index 0bb897d..39433a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use clap::{ArgAction, Parser}; +use clap::{Parser}; use regex::Regex; mod ics; @@ -18,8 +18,8 @@ struct Args { semester: Option, /// Export to iCalendar format (.ics) - #[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)] - export: bool, + #[clap(short, long)] + export: Option, } #[tokio::main] @@ -51,8 +51,14 @@ async fn main() { println!("Fetch informations about the year..."); let info = info::info().await; - println!("Build the ICS file..."); - let builded_timetable = timetable::build(timetable, info); + if args.export.is_some() { + // Export the calendar + println!("Build the ICS file..."); + let builded_timetable = timetable::build(timetable, info); - ics::export(builded_timetable, "target/debug.ics"); + ics::export(builded_timetable, &args.export.unwrap()); + } else { + // Show the calendar + println!("Displaying...") + } }