ask for path, support extension

This commit is contained in:
Mylloon 2022-08-17 14:38:31 +02:00
parent ea9c271b2c
commit 182933226e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 18 additions and 7 deletions

View file

@ -57,7 +57,12 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &str) {
calendar.add_event(event); 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 /// Transform the datetime from chrono to the ICS format

View file

@ -1,4 +1,4 @@
use clap::{ArgAction, Parser}; use clap::{Parser};
use regex::Regex; use regex::Regex;
mod ics; mod ics;
@ -18,8 +18,8 @@ struct Args {
semester: Option<i8>, semester: Option<i8>,
/// Export to iCalendar format (.ics) /// Export to iCalendar format (.ics)
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)] #[clap(short, long)]
export: bool, export: Option<String>,
} }
#[tokio::main] #[tokio::main]
@ -51,8 +51,14 @@ async fn main() {
println!("Fetch informations about the year..."); println!("Fetch informations about the year...");
let info = info::info().await; let info = info::info().await;
if args.export.is_some() {
// Export the calendar
println!("Build the ICS file..."); println!("Build the ICS file...");
let builded_timetable = timetable::build(timetable, info); 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...")
}
} }