Merge remote-tracking branch 'origin/main' into partial-solution-macro
This commit is contained in:
commit
6d22d33160
13 changed files with 29 additions and 25 deletions
|
@ -60,7 +60,9 @@ Every [solution](https://github.com/fspoettel/advent-of-code-rust/blob/main/src/
|
|||
### Download input & description for a day
|
||||
|
||||
> [!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
|
||||
# example: `cargo download 1`
|
||||
|
|
|
@ -1,4 +1 @@
|
|||
mod day;
|
||||
pub mod template;
|
||||
|
||||
pub use day::*;
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -2,10 +2,9 @@ use advent_of_code::template::commands::{all, download, read, scaffold, solve};
|
|||
use args::{parse, AppArguments};
|
||||
|
||||
mod args {
|
||||
use advent_of_code::template::Day;
|
||||
use std::process;
|
||||
|
||||
use advent_of_code::Day;
|
||||
|
||||
pub enum AppArguments {
|
||||
Download {
|
||||
day: Day,
|
||||
|
@ -15,6 +14,7 @@ mod args {
|
|||
},
|
||||
Scaffold {
|
||||
day: Day,
|
||||
download: bool,
|
||||
},
|
||||
Solve {
|
||||
day: Day,
|
||||
|
@ -44,6 +44,7 @@ mod args {
|
|||
},
|
||||
Some("scaffold") => AppArguments::Scaffold {
|
||||
day: args.free_from_str()?,
|
||||
download: args.contains("--download"),
|
||||
},
|
||||
Some("solve") => AppArguments::Solve {
|
||||
day: args.free_from_str()?,
|
||||
|
@ -80,7 +81,12 @@ fn main() {
|
|||
AppArguments::All { release, time } => all::handle(release, time),
|
||||
AppArguments::Download { day } => download::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 {
|
||||
day,
|
||||
release,
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
process::{Command, Output, Stdio},
|
||||
};
|
||||
|
||||
use crate::Day;
|
||||
use crate::template::Day;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AocCommandError {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::io;
|
||||
|
||||
use crate::template::{
|
||||
all_days,
|
||||
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) {
|
||||
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.
|
||||
mod child_commands {
|
||||
use super::{get_path_for_bin, Error};
|
||||
use crate::Day;
|
||||
use crate::template::Day;
|
||||
use std::{
|
||||
io::{BufRead, BufReader},
|
||||
path::Path,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::template::aoc_cli;
|
||||
use crate::Day;
|
||||
use crate::template::{aoc_cli, Day};
|
||||
use std::process;
|
||||
|
||||
pub fn handle(day: Day) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::process;
|
||||
|
||||
use crate::template::aoc_cli;
|
||||
use crate::Day;
|
||||
use crate::template::{aoc_cli, Day};
|
||||
|
||||
pub fn handle(day: Day) {
|
||||
if aoc_cli::check().is_err() {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
process,
|
||||
};
|
||||
|
||||
use crate::Day;
|
||||
use crate::template::Day;
|
||||
|
||||
const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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>) {
|
||||
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];
|
||||
|
|
|
@ -126,7 +126,7 @@ macro_rules! day {
|
|||
"`, expecting a value between 1 and 25"
|
||||
),
|
||||
);
|
||||
$crate::Day::__new_unchecked($day)
|
||||
$crate::template::Day::__new_unchecked($day)
|
||||
}};
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
use crate::Day;
|
||||
use std::{env, fs};
|
||||
|
||||
pub mod aoc_cli;
|
||||
pub mod commands;
|
||||
mod day;
|
||||
pub mod readme_benchmarks;
|
||||
pub mod runner;
|
||||
|
||||
pub use day::*;
|
||||
|
||||
pub const ANSI_ITALIC: &str = "\x1b[3m";
|
||||
pub const ANSI_BOLD: &str = "\x1b[1m";
|
||||
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 {
|
||||
($day:expr) => {
|
||||
/// 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() {
|
||||
use advent_of_code::template::runner::*;
|
||||
|
@ -46,7 +48,7 @@ macro_rules! solution {
|
|||
}
|
||||
};
|
||||
($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() {
|
||||
use advent_of_code::template::runner::*;
|
||||
|
@ -55,7 +57,7 @@ macro_rules! solution {
|
|||
}
|
||||
};
|
||||
($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() {
|
||||
use advent_of_code::template::runner::*;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/// The approach taken is similar to how `aoc-readme-stars` handles this.
|
||||
use std::{fs, io};
|
||||
|
||||
use crate::Day;
|
||||
use crate::template::Day;
|
||||
|
||||
static MARKER: &str = "<!--- benchmarking table --->";
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/// Encapsulates code that interacts with solution functions.
|
||||
use crate::template::{aoc_cli, ANSI_ITALIC, ANSI_RESET};
|
||||
use crate::Day;
|
||||
use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET};
|
||||
use std::fmt::Display;
|
||||
use std::io::{stdout, Write};
|
||||
use std::process::Output;
|
||||
|
|
Loading…
Add table
Reference in a new issue