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]
|
||||
today = "run --quiet --release -- today"
|
||||
today = "run --quiet --release --features today -- today"
|
||||
scaffold = "run --quiet --release -- scaffold"
|
||||
download = "run --quiet --release -- download"
|
||||
read = "run --quiet --release -- read"
|
||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -10,15 +10,16 @@ publish = false
|
|||
[lib]
|
||||
doctest = false
|
||||
|
||||
[profile.dhat]
|
||||
inherits = "release"
|
||||
debug = 1
|
||||
|
||||
[features]
|
||||
today = ["chrono"]
|
||||
test_lib = []
|
||||
dhat-heap = ["dhat"]
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.31"
|
||||
chrono = { version = "0.4.31", optional = true }
|
||||
pico-args = "0.5.0"
|
||||
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
|
||||
|
||||
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
|
||||
# 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},
|
||||
Day,
|
||||
};
|
||||
use advent_of_code::template::commands::{all, download, read, scaffold, solve};
|
||||
use args::{parse, AppArguments};
|
||||
|
||||
#[cfg(feature = "today")]
|
||||
use advent_of_code::template::Day;
|
||||
#[cfg(feature = "today")]
|
||||
use std::process;
|
||||
|
||||
mod args {
|
||||
use advent_of_code::template::Day;
|
||||
use std::process;
|
||||
|
@ -21,7 +21,6 @@ mod args {
|
|||
day: Day,
|
||||
download: bool,
|
||||
},
|
||||
Today,
|
||||
Solve {
|
||||
day: Day,
|
||||
release: bool,
|
||||
|
@ -33,6 +32,8 @@ mod args {
|
|||
release: bool,
|
||||
time: bool,
|
||||
},
|
||||
#[cfg(feature = "today")]
|
||||
Today,
|
||||
}
|
||||
|
||||
pub fn parse() -> Result<AppArguments, Box<dyn std::error::Error>> {
|
||||
|
@ -60,6 +61,7 @@ mod args {
|
|||
time: args.contains("--time"),
|
||||
dhat: args.contains("--dhat"),
|
||||
},
|
||||
#[cfg(feature = "today")]
|
||||
Some("today") => AppArguments::Today,
|
||||
Some(x) => {
|
||||
eprintln!("Unknown command: {x}");
|
||||
|
@ -103,6 +105,7 @@ fn main() {
|
|||
dhat,
|
||||
submit,
|
||||
} => solve::handle(day, release, time, dhat, submit),
|
||||
#[cfg(feature = "today")]
|
||||
AppArguments::Today => {
|
||||
match Day::today() {
|
||||
Some(day) => {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use chrono::{Datelike, Local};
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
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).
|
||||
///
|
||||
/// # Display
|
||||
|
@ -38,6 +40,7 @@ impl Day {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "today")]
|
||||
impl Day {
|
||||
/// Returns the current day if it's between the 1st and the 25th of december, `None` otherwise.
|
||||
pub fn today() -> Option<Self> {
|
||||
|
|
Loading…
Add table
Reference in a new issue