refactor: use feature flag for chrono
This commit is contained in:
parent
764d8a2505
commit
921dab6a76
5 changed files with 31 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
||||||
[alias]
|
[alias]
|
||||||
today = "run --quiet --release -- today"
|
today = "run --quiet --release --features today -- today"
|
||||||
scaffold = "run --quiet --release -- scaffold"
|
scaffold = "run --quiet --release -- scaffold"
|
||||||
download = "run --quiet --release -- download"
|
download = "run --quiet --release -- download"
|
||||||
read = "run --quiet --release -- read"
|
read = "run --quiet --release -- read"
|
||||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -10,15 +10,16 @@ publish = false
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
|
[profile.dhat]
|
||||||
|
inherits = "release"
|
||||||
|
debug = 1
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
today = ["chrono"]
|
||||||
test_lib = []
|
test_lib = []
|
||||||
dhat-heap = ["dhat"]
|
dhat-heap = ["dhat"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.31"
|
chrono = { version = "0.4.31", optional = true }
|
||||||
pico-args = "0.5.0"
|
pico-args = "0.5.0"
|
||||||
dhat = { version = "0.3.2", optional = true }
|
dhat = { version = "0.3.2", optional = true }
|
||||||
|
|
||||||
[profile.dhat]
|
|
||||||
inherits = "release"
|
|
||||||
debug = 1
|
|
||||||
|
|
11
README.md
11
README.md
|
@ -161,7 +161,16 @@ cargo read <day>
|
||||||
|
|
||||||
### Scaffold, download and read in one go
|
### Scaffold, download and read in one go
|
||||||
|
|
||||||
This command runs `cargo scaffold --download`, and `cargo read` for the current day.
|
> [!IMPORTANT]
|
||||||
|
> This command requires [installing the aoc-cli crate](#configure-aoc-cli-integration).
|
||||||
|
|
||||||
|
During december, the `today` shorthand command can be used to:
|
||||||
|
|
||||||
|
- scaffold a solution for the current day
|
||||||
|
- download its input
|
||||||
|
- and read the puzzle
|
||||||
|
|
||||||
|
in one go.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# example: `cargo today` on December 1st
|
# example: `cargo today` on December 1st
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,11 +1,11 @@
|
||||||
use std::process;
|
use advent_of_code::template::commands::{all, download, read, scaffold, solve};
|
||||||
|
|
||||||
use advent_of_code::template::{
|
|
||||||
commands::{all, download, read, scaffold, solve},
|
|
||||||
Day,
|
|
||||||
};
|
|
||||||
use args::{parse, AppArguments};
|
use args::{parse, AppArguments};
|
||||||
|
|
||||||
|
#[cfg(feature = "today")]
|
||||||
|
use advent_of_code::template::Day;
|
||||||
|
#[cfg(feature = "today")]
|
||||||
|
use std::process;
|
||||||
|
|
||||||
mod args {
|
mod args {
|
||||||
use advent_of_code::template::Day;
|
use advent_of_code::template::Day;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
@ -21,7 +21,6 @@ mod args {
|
||||||
day: Day,
|
day: Day,
|
||||||
download: bool,
|
download: bool,
|
||||||
},
|
},
|
||||||
Today,
|
|
||||||
Solve {
|
Solve {
|
||||||
day: Day,
|
day: Day,
|
||||||
release: bool,
|
release: bool,
|
||||||
|
@ -33,6 +32,8 @@ mod args {
|
||||||
release: bool,
|
release: bool,
|
||||||
time: bool,
|
time: bool,
|
||||||
},
|
},
|
||||||
|
#[cfg(feature = "today")]
|
||||||
|
Today,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse() -> Result<AppArguments, Box<dyn std::error::Error>> {
|
pub fn parse() -> Result<AppArguments, Box<dyn std::error::Error>> {
|
||||||
|
@ -60,6 +61,7 @@ mod args {
|
||||||
time: args.contains("--time"),
|
time: args.contains("--time"),
|
||||||
dhat: args.contains("--dhat"),
|
dhat: args.contains("--dhat"),
|
||||||
},
|
},
|
||||||
|
#[cfg(feature = "today")]
|
||||||
Some("today") => AppArguments::Today,
|
Some("today") => AppArguments::Today,
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
eprintln!("Unknown command: {x}");
|
eprintln!("Unknown command: {x}");
|
||||||
|
@ -103,6 +105,7 @@ fn main() {
|
||||||
dhat,
|
dhat,
|
||||||
submit,
|
submit,
|
||||||
} => solve::handle(day, release, time, dhat, submit),
|
} => solve::handle(day, release, time, dhat, submit),
|
||||||
|
#[cfg(feature = "today")]
|
||||||
AppArguments::Today => {
|
AppArguments::Today => {
|
||||||
match Day::today() {
|
match Day::today() {
|
||||||
Some(day) => {
|
Some(day) => {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use chrono::{Datelike, Local};
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
#[cfg(feature = "today")]
|
||||||
|
use chrono::{Datelike, Local};
|
||||||
|
|
||||||
/// A valid day number of advent (i.e. an integer in range 1 to 25).
|
/// A valid day number of advent (i.e. an integer in range 1 to 25).
|
||||||
///
|
///
|
||||||
/// # Display
|
/// # Display
|
||||||
|
@ -38,6 +40,7 @@ impl Day {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "today")]
|
||||||
impl Day {
|
impl Day {
|
||||||
/// Returns the current day if it's between the 1st and the 25th of december, `None` otherwise.
|
/// Returns the current day if it's between the 1st and the 25th of december, `None` otherwise.
|
||||||
pub fn today() -> Option<Self> {
|
pub fn today() -> Option<Self> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue