2022-12-01 16:30:59 -05:00
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
mod days;
|
|
|
|
|
|
|
|
fn help() {
|
2022-12-07 14:08:12 -05:00
|
|
|
println!(
|
|
|
|
"Usage: {} day-number <day-number>...",
|
|
|
|
env!("CARGO_BIN_NAME")
|
|
|
|
);
|
2022-12-01 16:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run_day(number: i32) -> Result<()> {
|
|
|
|
match number {
|
|
|
|
1 => {
|
|
|
|
days::day1::run()?;
|
|
|
|
}
|
2022-12-02 08:56:29 -05:00
|
|
|
2 => {
|
|
|
|
days::day2::run()?;
|
2022-12-05 10:10:12 -05:00
|
|
|
}
|
2022-12-05 09:19:26 -05:00
|
|
|
3 => {
|
|
|
|
days::day3::run()?;
|
2022-12-05 10:10:12 -05:00
|
|
|
}
|
|
|
|
4 => {
|
|
|
|
days::day4::run()?;
|
|
|
|
}
|
2022-12-05 10:54:06 -05:00
|
|
|
5 => {
|
|
|
|
days::day5::run()?;
|
|
|
|
}
|
2022-12-06 00:54:39 -05:00
|
|
|
6 => {
|
|
|
|
days::day6::run()?;
|
|
|
|
}
|
2022-12-07 14:08:12 -05:00
|
|
|
7 => {
|
|
|
|
days::day7::run()?;
|
|
|
|
}
|
2022-12-08 13:32:12 -05:00
|
|
|
8 => {
|
|
|
|
days::day8::run()?;
|
|
|
|
}
|
2022-12-09 14:40:25 -05:00
|
|
|
9 => {
|
|
|
|
days::day9::run()?;
|
|
|
|
}
|
2022-12-10 02:32:57 -05:00
|
|
|
10 => {
|
|
|
|
days::day10::run()?;
|
|
|
|
}
|
2022-12-12 15:01:45 -05:00
|
|
|
11 => {
|
|
|
|
days::day11::run()?;
|
|
|
|
}
|
2022-12-13 11:46:22 -05:00
|
|
|
12 => {
|
|
|
|
days::day12::run()?;
|
|
|
|
}
|
2022-12-01 16:30:59 -05:00
|
|
|
_ => return Err(anyhow!("Invalid day provided")),
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
|
|
|
|
match args.len() {
|
2022-12-07 14:08:12 -05:00
|
|
|
0 => {
|
|
|
|
help();
|
|
|
|
return Err(anyhow!("No arguments provided"));
|
2022-12-01 16:30:59 -05:00
|
|
|
}
|
2022-12-07 14:08:12 -05:00
|
|
|
1 => {
|
2022-12-01 16:30:59 -05:00
|
|
|
help();
|
2022-12-07 14:08:12 -05:00
|
|
|
return Err(anyhow!("Not enough arguments provided"));
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
for val in args[1..].iter() {
|
|
|
|
let number: i32 = match val.parse() {
|
|
|
|
Ok(n) => n,
|
|
|
|
Err(_) => {
|
|
|
|
help();
|
|
|
|
return Err(anyhow!("Argument {} is not an integer", val));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
println!("Day {}", number);
|
|
|
|
run_day(number)?;
|
2022-12-08 13:32:12 -05:00
|
|
|
println!();
|
2022-12-07 14:08:12 -05:00
|
|
|
}
|
2022-12-01 16:30:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|