git-heatmap/src/cli.rs

52 lines
1.4 KiB
Rust

use std::path::PathBuf;
use chrono::{Duration, Local};
use clap::{arg, Parser, ValueHint};
use crate::heatmap::{ColorLogic, HeatmapColors};
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
#[command(version, about, author, long_about = None)]
pub struct CliArgs {
#[arg(long("root-dir"), value_hint = ValueHint::DirPath)]
pub root_dir: Option<PathBuf>,
#[arg(short, long, num_args(0..))]
pub authors: Option<Vec<String>>,
#[arg(short, long, default_value = "")]
pub char: char,
#[arg(long("color"), value_enum, default_value_t = HeatmapColors::Green)]
pub color_scheme: HeatmapColors,
#[arg(short, long, num_args(0..), value_hint = ValueHint::DirPath)]
pub repos: Option<Vec<PathBuf>>,
#[arg(short('i'), long("ignore"), num_args(0..))]
pub ignored_repos: Option<Vec<String>>,
#[arg(short, long, num_args(0..))]
pub branches: Option<Vec<String>>,
#[arg(long("since"), default_value_t = get_since_date())]
pub since: String,
#[arg(long("until"))]
pub until: Option<String>,
#[arg(long("split-months"), help("Split months"), default_value_t = false)]
pub split_months: bool,
#[arg(long("no-merges"), default_value_t = false)]
pub no_merges: bool,
#[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByWeight)]
pub counting: ColorLogic,
}
fn get_since_date() -> String {
let date = Local::now() - Duration::days(365);
date.format("%Y-%m-%d").to_string()
}