From 7380364c1c3f319e8abca75db59a9b236b9bd525 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 23 Apr 2023 00:22:19 +0200 Subject: [PATCH] cherry-pick of Paris8/cal8tor:0a5dd3c8f007ee69b720c40d9a761f4d0df6f19d --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/ics.rs | 14 +++++++------- src/main.rs | 7 ++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e3f970..37e077f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "cal8tor" -version = "0.4.2" +version = "0.4.3" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index f5fd9c4..719978a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cal8tor" -version = "0.4.2" +version = "0.4.3" authors = ["Mylloon"] edition = "2021" description = "Extractor of the calendar of the IT degree of university Paris 8" diff --git a/src/ics.rs b/src/ics.rs index f4c9ca9..f180d81 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -5,7 +5,7 @@ use ics::{ Event, ICalendar, Standard, }; -pub fn export(courses: Vec, filename: String) { +pub fn export(courses: Vec, filename: &mut String) { let mut calendar = ICalendar::new("2.0", "cal8tor"); // Add Europe/Paris timezone @@ -61,12 +61,12 @@ pub fn export(courses: Vec, filename: String) calendar.add_event(event); } - calendar - .save_file(match filename { - x if x.ends_with(".ics") => x, - x => format!("{}.ics", x), - }) - .unwrap(); + // Add the extension if needed + if !filename.ends_with(".ics") { + *filename = format!("{}.ics", filename) + }; + + calendar.save_file(filename).unwrap(); } /// Transform the datetime from chrono to the ICS format diff --git a/src/main.rs b/src/main.rs index 3601041..189eb78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,11 +66,12 @@ async fn main() { if args.export.is_some() { // Export the calendar - let filename = args.export.unwrap(); - println!("Fichier .ICS construit et exporté ici : {}...", filename); + let mut filename = args.export.unwrap(); let builded_timetable = timetable::build(timetable, info); - ics::export(builded_timetable, filename); + ics::export(builded_timetable, &mut filename); + + println!("Fichier .ICS construit et exporté => {}", filename); } else { // Show the calendar println!("Affichage...");