63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
|
use std::fs::read_to_string;
|
||
|
use std::time::SystemTime;
|
||
|
use chrono::Datelike;
|
||
|
use clap::{App, Arg, SubCommand};
|
||
|
use crate::day1::Day1;
|
||
|
use crate::day::Day;
|
||
|
|
||
|
mod day;
|
||
|
mod day1;
|
||
|
|
||
|
fn load_input(day: &str) -> String {
|
||
|
read_to_string(format!("./input/day{}", day)).expect("Could not load input")
|
||
|
}
|
||
|
|
||
|
fn run_day(days: &Vec<Box<dyn Day>>, day: usize) {
|
||
|
if let Some(d) = days.get(day - 1) {
|
||
|
let day_code = d.clone();
|
||
|
println!("Running day {}!", day);
|
||
|
println!("\tPart 1: {}", d.part1());
|
||
|
println!("\tPart 2: {}", day_code.part2());
|
||
|
} else {
|
||
|
eprintln!("Day {} is not available!", day);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let matches = App::new("AOC Time!")
|
||
|
.version("1.0")
|
||
|
.author("J00LZ")
|
||
|
.about("How to overengineer AOC in a single program...")
|
||
|
.arg(Arg::with_name("v")
|
||
|
.short("v")
|
||
|
.multiple(true)
|
||
|
.help("Sets the level of verbosity"))
|
||
|
.arg(Arg::with_name("all")
|
||
|
.short("a")
|
||
|
.long("all")
|
||
|
.help("run all available days"))
|
||
|
.arg(Arg::with_name("DAY")
|
||
|
.takes_value(true)
|
||
|
.multiple(true))
|
||
|
.get_matches();
|
||
|
|
||
|
let days: Vec<Box<dyn Day>> = vec![Box::new(Day1::init(load_input("1")))];
|
||
|
|
||
|
let verbosity = matches.occurrences_of("v");
|
||
|
if matches.is_present("all") {
|
||
|
let l = days.len();
|
||
|
println!("running {} days!", l);
|
||
|
for v in 1..l + 1 {
|
||
|
run_day(&days, v);
|
||
|
}
|
||
|
} else if let Some(d) = matches.values_of("DAY") {
|
||
|
let d = d.map(|x| x.parse::<i32>().expect("Did not provide an int!"));
|
||
|
for v in d {
|
||
|
run_day(&days, v as usize);
|
||
|
}
|
||
|
} else {
|
||
|
let v = chrono::Local::now().day();
|
||
|
run_day(&days, v as usize)
|
||
|
}
|
||
|
}
|