use clap::{AppSettings, Parser};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[clap(
name = "lintje",
version,
verbatim_doc_comment,
setting(AppSettings::DeriveDisplayOrder)
)]
pub struct Lint {
#[clap(long = "no-branch", parse(from_flag = std::ops::Not::not))]
pub branch_validation: bool,
#[clap(long = "no-hints", parse(from_flag = std::ops::Not::not))]
pub hints: bool,
#[clap(long = "color")]
pub color: bool,
#[clap(long = "no-color")]
pub no_color: bool,
#[clap(long, parse(from_os_str))]
pub hook_message_file: Option<PathBuf>,
#[clap(long)]
pub debug: bool,
#[clap(name = "commit (range)")]
pub selection: Option<String>,
}
impl Lint {
pub fn color(&self) -> bool {
if self.no_color {
return false;
}
if self.color {
return true;
}
false }
}
#[derive(Debug)]
pub struct Options {
pub debug: bool,
pub color: bool,
pub hints: bool,
}
#[cfg(test)]
mod tests {
use super::Lint;
use clap::Parser;
#[test]
fn test_color_flags() {
assert!(!Lint::parse_from(["lintje", "--color", "--no-color"]).color());
assert!(Lint::parse_from(["lintje", "--color"]).color());
assert!(!Lint::parse_from(["lintje", "--no-color"]).color());
assert!(!Lint::parse_from(["lintje"]).color());
}
}