wip: cli support
This commit is contained in:
parent
44846562be
commit
c844e4a0c5
1 changed files with 29 additions and 11 deletions
40
src/main.rs
40
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::{ArgAction, Parser};
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
mod ics;
|
mod ics;
|
||||||
mod info;
|
mod info;
|
||||||
|
@ -8,23 +9,40 @@ mod utils;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(version, about, long_about = None)]
|
#[clap(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Class
|
/// The class you want to get the timetable
|
||||||
#[clap(short, long, value_parser)]
|
#[clap(value_parser)]
|
||||||
class: i8,
|
class: String,
|
||||||
|
|
||||||
/// Subgroup if you have one, for example in `L1-A`, specify here the `A`
|
/// Export to iCalendar format (.ics)
|
||||||
#[clap(short, long, value_parser)]
|
#[clap(short, long, action = ArgAction::SetTrue, default_value_t = false)]
|
||||||
letter: Option<char>,
|
export: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
println!("class: L{}{}", args.class, args.letter.unwrap_or_default());
|
let matches = Regex::new(r"[Ll](?P<year>\d)-?(?P<letter>.)?")
|
||||||
|
.unwrap()
|
||||||
|
.captures(&args.class)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
/* println!("Fetch the timetable...");
|
let year = matches
|
||||||
let timetable = timetable::timetable(3, 1, None).await;
|
.name("year")
|
||||||
|
.unwrap()
|
||||||
|
.as_str()
|
||||||
|
.parse::<i8>()
|
||||||
|
.unwrap();
|
||||||
|
let letter = matches
|
||||||
|
.name("letter")
|
||||||
|
.map(|c| c.as_str().chars().next().expect("Error in letter"));
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Fetch the timetable for L{}{}...",
|
||||||
|
year,
|
||||||
|
letter.unwrap_or_default()
|
||||||
|
);
|
||||||
|
let timetable = timetable::timetable(year, 1, letter).await;
|
||||||
|
|
||||||
println!("Fetch informations about the year...");
|
println!("Fetch informations about the year...");
|
||||||
let info = info::info().await;
|
let info = info::info().await;
|
||||||
|
@ -32,5 +50,5 @@ async fn main() {
|
||||||
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, "target/debug.ics");
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue