42 lines
855 B
Rust
42 lines
855 B
Rust
|
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()?;
|
||
|
}
|
||
|
_ => return Err(anyhow!("Invalid day provided")),
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
fn main() -> Result<()> {
|
||
|
let args: Vec<String> = env::args().collect();
|
||
|
|
||
|
match args.len() {
|
||
|
2 => {
|
||
|
let number: i32 = match args[1].parse() {
|
||
|
Ok(n) => n,
|
||
|
Err(_) => {
|
||
|
help();
|
||
|
return Err(anyhow!("Argument is not an integer"));
|
||
|
}
|
||
|
};
|
||
|
run_day(number)?;
|
||
|
}
|
||
|
_ => {
|
||
|
help();
|
||
|
return Err(anyhow!("Invalid arguments provided"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Ok(())
|
||
|
}
|