Merge remote-tracking branch 'origin/main' into partial-solution-macro

This commit is contained in:
Felix Spöttel 2023-12-05 22:49:41 +01:00
commit 6d22d33160
13 changed files with 29 additions and 25 deletions

View file

@ -60,7 +60,9 @@ Every [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/
### Download input & description for a day ### Download input & description for a day
> [!IMPORTANT] > [!IMPORTANT]
> This command requires [installing the aoc-cli crate](#configure-aoc-cli-integration). > This requires [installing the aoc-cli crate](#configure-aoc-cli-integration).
You can automatically download puzzle inputs and description by either appending the `--download` flag to `scaffold` (e.g. `cargo scaffold 4 --download`) or with the separate `download` command:
```sh ```sh
# example: `cargo download 1` # example: `cargo download 1`

View file

@ -1,4 +1 @@
mod day;
pub mod template; pub mod template;
pub use day::*;

View file

@ -2,10 +2,9 @@ use advent_of_code::template::commands::{all, download, read, scaffold, solve};
use args::{parse, AppArguments}; use args::{parse, AppArguments};
mod args { mod args {
use advent_of_code::template::Day;
use std::process; use std::process;
use advent_of_code::Day;
pub enum AppArguments { pub enum AppArguments {
Download { Download {
day: Day, day: Day,
@ -15,6 +14,7 @@ mod args {
}, },
Scaffold { Scaffold {
day: Day, day: Day,
download: bool,
}, },
Solve { Solve {
day: Day, day: Day,
@ -44,6 +44,7 @@ mod args {
}, },
Some("scaffold") => AppArguments::Scaffold { Some("scaffold") => AppArguments::Scaffold {
day: args.free_from_str()?, day: args.free_from_str()?,
download: args.contains("--download"),
}, },
Some("solve") => AppArguments::Solve { Some("solve") => AppArguments::Solve {
day: args.free_from_str()?, day: args.free_from_str()?,
@ -80,7 +81,12 @@ fn main() {
AppArguments::All { release, time } => all::handle(release, time), AppArguments::All { release, time } => all::handle(release, time),
AppArguments::Download { day } => download::handle(day), AppArguments::Download { day } => download::handle(day),
AppArguments::Read { day } => read::handle(day), AppArguments::Read { day } => read::handle(day),
AppArguments::Scaffold { day } => scaffold::handle(day), AppArguments::Scaffold { day, download } => {
scaffold::handle(day);
if download {
download::handle(day);
}
}
AppArguments::Solve { AppArguments::Solve {
day, day,
release, release,

View file

@ -4,7 +4,7 @@ use std::{
process::{Command, Output, Stdio}, process::{Command, Output, Stdio},
}; };
use crate::Day; use crate::template::Day;
#[derive(Debug)] #[derive(Debug)]
pub enum AocCommandError { pub enum AocCommandError {

View file

@ -1,10 +1,10 @@
use std::io; use std::io;
use crate::template::{ use crate::template::{
all_days,
readme_benchmarks::{self, Timings}, readme_benchmarks::{self, Timings},
ANSI_BOLD, ANSI_ITALIC, ANSI_RESET, Day, ANSI_BOLD, ANSI_ITALIC, ANSI_RESET,
}; };
use crate::{all_days, Day};
pub fn handle(is_release: bool, is_timed: bool) { pub fn handle(is_release: bool, is_timed: bool) {
let mut timings: Vec<Timings> = vec![]; let mut timings: Vec<Timings> = vec![];
@ -65,7 +65,7 @@ pub fn get_path_for_bin(day: Day) -> String {
/// This module encapsulates interaction with these binaries, both invoking them as well as parsing the timing output. /// This module encapsulates interaction with these binaries, both invoking them as well as parsing the timing output.
mod child_commands { mod child_commands {
use super::{get_path_for_bin, Error}; use super::{get_path_for_bin, Error};
use crate::Day; use crate::template::Day;
use std::{ use std::{
io::{BufRead, BufReader}, io::{BufRead, BufReader},
path::Path, path::Path,

View file

@ -1,5 +1,4 @@
use crate::template::aoc_cli; use crate::template::{aoc_cli, Day};
use crate::Day;
use std::process; use std::process;
pub fn handle(day: Day) { pub fn handle(day: Day) {

View file

@ -1,7 +1,6 @@
use std::process; use std::process;
use crate::template::aoc_cli; use crate::template::{aoc_cli, Day};
use crate::Day;
pub fn handle(day: Day) { pub fn handle(day: Day) {
if aoc_cli::check().is_err() { if aoc_cli::check().is_err() {

View file

@ -4,7 +4,7 @@ use std::{
process, process,
}; };
use crate::Day; use crate::template::Day;
const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER); const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER);

View file

@ -1,6 +1,6 @@
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::Day; use crate::template::Day;
pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) { pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) {
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()]; let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];

View file

@ -126,7 +126,7 @@ macro_rules! day {
"`, expecting a value between 1 and 25" "`, expecting a value between 1 and 25"
), ),
); );
$crate::Day::__new_unchecked($day) $crate::template::Day::__new_unchecked($day)
}}; }};
} }

View file

@ -1,11 +1,13 @@
use crate::Day;
use std::{env, fs}; use std::{env, fs};
pub mod aoc_cli; pub mod aoc_cli;
pub mod commands; pub mod commands;
mod day;
pub mod readme_benchmarks; pub mod readme_benchmarks;
pub mod runner; pub mod runner;
pub use day::*;
pub const ANSI_ITALIC: &str = "\x1b[3m"; pub const ANSI_ITALIC: &str = "\x1b[3m";
pub const ANSI_BOLD: &str = "\x1b[1m"; pub const ANSI_BOLD: &str = "\x1b[1m";
pub const ANSI_RESET: &str = "\x1b[0m"; pub const ANSI_RESET: &str = "\x1b[0m";
@ -36,7 +38,7 @@ pub fn read_file_part(folder: &str, day: Day, part: u8) -> String {
macro_rules! solution { macro_rules! solution {
($day:expr) => { ($day:expr) => {
/// The current day. /// The current day.
const DAY: advent_of_code::Day = advent_of_code::day!($day); const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
fn main() { fn main() {
use advent_of_code::template::runner::*; use advent_of_code::template::runner::*;
@ -46,7 +48,7 @@ macro_rules! solution {
} }
}; };
($day:expr, 1) => { /// Allows solving part one in isolation ($day:expr, 1) => { /// Allows solving part one in isolation
const DAY: advent_of_code::Day = advent_of_code::day!($day); const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
fn main() { fn main() {
use advent_of_code::template::runner::*; use advent_of_code::template::runner::*;
@ -55,7 +57,7 @@ macro_rules! solution {
} }
}; };
($day:expr, 2) => { /// Allows solving part two in isolation ($day:expr, 2) => { /// Allows solving part two in isolation
const DAY: advent_of_code::Day = advent_of_code::day!($day); const DAY: advent_of_code::template::Day = advent_of_code::day!($day);
fn main() { fn main() {
use advent_of_code::template::runner::*; use advent_of_code::template::runner::*;

View file

@ -2,7 +2,7 @@
/// The approach taken is similar to how `aoc-readme-stars` handles this. /// The approach taken is similar to how `aoc-readme-stars` handles this.
use std::{fs, io}; use std::{fs, io};
use crate::Day; use crate::template::Day;
static MARKER: &str = "<!--- benchmarking table --->"; static MARKER: &str = "<!--- benchmarking table --->";

View file

@ -1,6 +1,5 @@
/// Encapsulates code that interacts with solution functions. /// Encapsulates code that interacts with solution functions.
use crate::template::{aoc_cli, ANSI_ITALIC, ANSI_RESET}; use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET};
use crate::Day;
use std::fmt::Display; use std::fmt::Display;
use std::io::{stdout, Write}; use std::io::{stdout, Write};
use std::process::Output; use std::process::Output;