diff --git a/src/main.rs b/src/main.rs index 5134f1b..4f04373 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ pub mod utils; struct Cli { /// Sets the cookie to send to fetch input data #[arg(short, long, value_name = "AUTH")] - auth: String, + auth: Option, /// The subcommand to run #[command(subcommand)] subcommand: Subcommands, @@ -62,9 +62,9 @@ enum Subcommands { warmup: u32, /// The amount of times to run n: u32, - /// If used, then the large input will be solved and checked rather than the real one - #[arg(short, long, group = "inputs")] - large: bool, + /// Allows you to control the type of input used + #[arg(short, long)] + input: InputType, }, /// Fetches and prints the given input for a specified day Input { @@ -84,6 +84,7 @@ enum Subcommands { async fn main() { let cli = Cli::parse(); let client = reqwest::Client::new(); + let auth = cli.auth.unwrap_or(std::env::var("AOC_SESSION").ok().expect("no auth provided")); match cli.subcommand { Subcommands::Solve { @@ -92,8 +93,8 @@ async fn main() { input: input_type, } => { let (input, solution) = match input_type { - InputType::Normal => (fetcher::fetch_input(cli.auth, day).await, None), - InputType::Example => fetcher::fetch_example(cli.auth, day, part).await, + InputType::Normal => (fetcher::fetch_input(auth, day).await, None), + InputType::Example => fetcher::fetch_example(auth, day, part).await, InputType::Large => fetcher::fetch_large(day, part).await, InputType::Custom => (std::fs::read_to_string({ let mut p = std::env::current_dir().unwrap(); p.push("input.txt"); p }).unwrap(), None), }; @@ -148,11 +149,13 @@ async fn main() { part, warmup, n, - large, + input: input_type, } => { - let input = match large { - false => fetcher::fetch_input(cli.auth, day).await, - true => fetcher::fetch_large(day, part).await.0, + let input = match input_type { + InputType::Normal => fetcher::fetch_input(auth, day).await, + InputType::Example => fetcher::fetch_example(auth, day, part).await.0, + InputType::Large => fetcher::fetch_large(day, part).await.0, + InputType::Custom => std::fs::read_to_string({ let mut p = std::env::current_dir().unwrap(); p.push("input.txt"); p }).unwrap(), }; let mut day: Box = match day { @@ -177,6 +180,7 @@ async fn main() { _ => panic!("Invalid day #"), }; let mut timings = Vec::::new(); + let large = input_type == InputType::Large; for _ in 1..warmup { day.solve(part, large); } @@ -218,7 +222,7 @@ async fn main() { Subcommands::Input { day } => { let response = client .get(format!("https://adventofcode.com/2023/day/{day}/input")) - .header("Cookie", format!("session={auth}", auth = cli.auth)) + .header("Cookie", format!("session={auth}")) .send() .await .unwrap() @@ -231,7 +235,7 @@ async fn main() { println!("{response}"); } Subcommands::Example { day, part } => { - let (input, solution) = fetcher::fetch_example(cli.auth, day, part).await; + let (input, solution) = fetcher::fetch_example(auth, day, part).await; let input_width = input.lines().map(|l| l.len()).max().unwrap(); let mut stylized_input = String::new(); stylized_input.push('+');