feat: command to automatically generate a file for the new day

This commit is contained in:
Ashhhleyyy 2022-12-01 20:23:11 +00:00
parent a008c64177
commit e7bbe790a5
Signed by: ash
GPG key ID: 83B789081A0878FB
3 changed files with 81 additions and 0 deletions

23
Cargo.lock generated
View file

@ -23,6 +23,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"aoc_proc", "aoc_proc",
"color-eyre", "color-eyre",
"time",
"ureq", "ureq",
] ]
@ -314,6 +315,12 @@ dependencies = [
"untrusted", "untrusted",
] ]
[[package]]
name = "serde"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
[[package]] [[package]]
name = "sharded-slab" name = "sharded-slab"
version = "0.1.4" version = "0.1.4"
@ -349,6 +356,22 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"serde",
"time-core",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"

View file

@ -12,3 +12,4 @@ members = ["aoc_proc"]
color-eyre = "0.6.2" color-eyre = "0.6.2"
aoc_proc = { path = "aoc_proc" } aoc_proc = { path = "aoc_proc" }
ureq = "2.5.0" ureq = "2.5.0"
time = "0.3.17"

57
src/bin/create_day.rs Normal file
View file

@ -0,0 +1,57 @@
use std::path::Path;
use color_eyre::{Result, eyre::bail};
const TEMPLATE: &str = r#"
use aoc_2022::prelude::*;
type Input = ();
fn parse(s: &str) -> Result<Input> {
Ok(())
}
#[aoc(day = {{ day }}, parse = parse)]
fn day_{{ day }}(mut input: Input) -> Result<()> {
// Part 1
println!("Part one: ");
// Part 2
println!("Part two: ");
Ok(())
}
"#;
fn main() -> Result<()> {
let day = std::env::args().nth(1);
let day = match day {
Some(day) => day.parse::<u8>()?,
None => {
let today = time::OffsetDateTime::now_utc().date();
if today.month() != time::Month::December {
bail!("Its not December yet!");
}
if today.day() > 25 {
bail!("Its after Christmas now :/");
}
today.day()
}
};
let output_path = Path::new("src").join("bin").join(format!("day_{day}.rs"));
if output_path.exists() {
bail!("today already exists!");
}
std::fs::write(output_path, TEMPLATE.replace("{{ day }}", &format!("{day}")))?;
println!("ready uwu :)");
Ok(())
}