Added today keyword for the until flag

master
Wynd 2025-12-11 01:25:03 +02:00
parent 8f4a8c18f9
commit 1d97cbfa45
3 changed files with 12 additions and 3 deletions

View File

@ -84,5 +84,6 @@ $ git-heatmap -a "username" -a "other"
$ git-heatmap --since "2013-08-23"
# or choose a time span, both --since and --until must use a YYYY-MM-DD format
# --until can optionally use `today` as a keyword for the current date
$ git-heatmap --since "2013-08-23" --until "2024-08-23"
```

View File

@ -32,7 +32,12 @@ pub struct CliArgs {
#[arg(long("since"), default_value_t = get_since_date())]
pub since: String,
#[arg(long("until"))]
#[arg(
long("until"),
help(
"Optional upper limit for the time slice being checked, defaults to 365 days after the `since` date.\n`today` can be used for current date."
)
)]
pub until: Option<String>,
#[arg(long("split-months"), help("Split months"), default_value_t = false)]
@ -74,4 +79,4 @@ pub struct CliArgs {
fn get_since_date() -> String {
let date = Local::now() - Duration::days(364);
date.format("%Y-%m-%d").to_string()
}
}

View File

@ -15,7 +15,10 @@ fn main() -> Result<()> {
.until
.clone()
.unwrap_or_else(|| libgitheatmap::get_default_until(since));
let until = NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap();
let until = match until.to_lowercase().as_str() {
"today" => chrono::Local::now().date_naive(),
_ => NaiveDate::parse_from_str(&until, "%Y-%m-%d").unwrap(),
};
let split_months = args.split_months;
let months_per_row = args.months_per_row;