forked from Anri/cal8tor
ask for path, support extension
This commit is contained in:
parent
ea9c271b2c
commit
182933226e
2 changed files with 18 additions and 7 deletions
|
@ -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
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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...")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue