use anyhow::{anyhow, Result}; use std::env; mod days; fn help() { println!( "Usage: {} day-number ...", env!("CARGO_BIN_NAME") ); } fn run_day(number: i32) -> Result<()> { match number { 1 => { days::day1::run()?; } 2 => { days::day2::run()?; } 3 => { days::day3::run()?; } 4 => { days::day4::run()?; } 5 => { days::day5::run()?; } 6 => { days::day6::run()?; } 7 => { days::day7::run()?; } 8 => { days::day8::run()?; } 9 => { days::day9::run()?; } 10 => { days::day10::run()?; } 11 => { days::day11::run()?; } 12 => { days::day12::run()?; } 13 => { days::day13::run()?; } 14 => { days::day14::run()?; } _ => return Err(anyhow!("Invalid day provided")), } Ok(()) } fn main() -> Result<()> { let args: Vec = env::args().collect(); match args.len() { 0 => { help(); return Err(anyhow!("No arguments provided")); } 1 => { help(); 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)?; println!(); } } } Ok(()) }