Improved auth + better benchmark input select
This commit is contained in:
parent
cd9d03ecd3
commit
d33a6fb539
1 changed files with 16 additions and 12 deletions
28
src/main.rs
28
src/main.rs
|
@ -26,7 +26,7 @@ pub mod utils;
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// Sets the cookie to send to fetch input data
|
/// Sets the cookie to send to fetch input data
|
||||||
#[arg(short, long, value_name = "AUTH")]
|
#[arg(short, long, value_name = "AUTH")]
|
||||||
auth: String,
|
auth: Option<String>,
|
||||||
/// The subcommand to run
|
/// The subcommand to run
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
subcommand: Subcommands,
|
subcommand: Subcommands,
|
||||||
|
@ -62,9 +62,9 @@ enum Subcommands {
|
||||||
warmup: u32,
|
warmup: u32,
|
||||||
/// The amount of times to run
|
/// The amount of times to run
|
||||||
n: u32,
|
n: u32,
|
||||||
/// If used, then the large input will be solved and checked rather than the real one
|
/// Allows you to control the type of input used
|
||||||
#[arg(short, long, group = "inputs")]
|
#[arg(short, long)]
|
||||||
large: bool,
|
input: InputType,
|
||||||
},
|
},
|
||||||
/// Fetches and prints the given input for a specified day
|
/// Fetches and prints the given input for a specified day
|
||||||
Input {
|
Input {
|
||||||
|
@ -84,6 +84,7 @@ enum Subcommands {
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
let auth = cli.auth.unwrap_or(std::env::var("AOC_SESSION").ok().expect("no auth provided"));
|
||||||
|
|
||||||
match cli.subcommand {
|
match cli.subcommand {
|
||||||
Subcommands::Solve {
|
Subcommands::Solve {
|
||||||
|
@ -92,8 +93,8 @@ async fn main() {
|
||||||
input: input_type,
|
input: input_type,
|
||||||
} => {
|
} => {
|
||||||
let (input, solution) = match input_type {
|
let (input, solution) = match input_type {
|
||||||
InputType::Normal => (fetcher::fetch_input(cli.auth, day).await, None),
|
InputType::Normal => (fetcher::fetch_input(auth, day).await, None),
|
||||||
InputType::Example => fetcher::fetch_example(cli.auth, day, part).await,
|
InputType::Example => fetcher::fetch_example(auth, day, part).await,
|
||||||
InputType::Large => fetcher::fetch_large(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),
|
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,
|
part,
|
||||||
warmup,
|
warmup,
|
||||||
n,
|
n,
|
||||||
large,
|
input: input_type,
|
||||||
} => {
|
} => {
|
||||||
let input = match large {
|
let input = match input_type {
|
||||||
false => fetcher::fetch_input(cli.auth, day).await,
|
InputType::Normal => fetcher::fetch_input(auth, day).await,
|
||||||
true => fetcher::fetch_large(day, part).await.0,
|
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<dyn Day> = match day {
|
let mut day: Box<dyn Day> = match day {
|
||||||
|
@ -177,6 +180,7 @@ async fn main() {
|
||||||
_ => panic!("Invalid day #"),
|
_ => panic!("Invalid day #"),
|
||||||
};
|
};
|
||||||
let mut timings = Vec::<Duration>::new();
|
let mut timings = Vec::<Duration>::new();
|
||||||
|
let large = input_type == InputType::Large;
|
||||||
for _ in 1..warmup {
|
for _ in 1..warmup {
|
||||||
day.solve(part, large);
|
day.solve(part, large);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +222,7 @@ async fn main() {
|
||||||
Subcommands::Input { day } => {
|
Subcommands::Input { day } => {
|
||||||
let response = client
|
let response = client
|
||||||
.get(format!("https://adventofcode.com/2023/day/{day}/input"))
|
.get(format!("https://adventofcode.com/2023/day/{day}/input"))
|
||||||
.header("Cookie", format!("session={auth}", auth = cli.auth))
|
.header("Cookie", format!("session={auth}"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -231,7 +235,7 @@ async fn main() {
|
||||||
println!("{response}");
|
println!("{response}");
|
||||||
}
|
}
|
||||||
Subcommands::Example { day, part } => {
|
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 input_width = input.lines().map(|l| l.len()).max().unwrap();
|
||||||
let mut stylized_input = String::new();
|
let mut stylized_input = String::new();
|
||||||
stylized_input.push('+');
|
stylized_input.push('+');
|
||||||
|
|
Loading…
Reference in a new issue