use clap::Parser;
use crate::reporter::OutputFormat;
use pedant_core::check_config::{CheckConfig, ConfigFile};
#[derive(Parser, Debug)]
#[command(name = "pedant")]
#[command(about = "An opinionated Rust linter, with special focus on AI-generated code")]
#[command(version)]
pub struct Cli {
#[arg(required_unless_present_any = ["stdin", "list_checks", "explain", "diff"])]
pub files: Vec<String>,
#[arg(long)]
pub stdin: bool,
#[arg(long)]
pub list_checks: bool,
#[arg(long, value_name = "CHECK")]
pub explain: Option<String>,
#[arg(short = 'd', long, default_value = "3")]
pub max_depth: usize,
#[arg(short = 'c', long)]
pub config: Option<String>,
#[arg(short = 'f', long, value_enum, default_value_t = OutputFormat::Text)]
pub format: OutputFormat,
#[arg(short = 'q', long)]
pub quiet: bool,
#[arg(long)]
pub no_nested_if: bool,
#[arg(long)]
pub no_if_in_match: bool,
#[arg(long)]
pub no_nested_match: bool,
#[arg(long)]
pub no_match_in_if: bool,
#[arg(long)]
pub no_else_chain: bool,
#[arg(long)]
pub capabilities: bool,
#[arg(long, num_args = 2, value_names = ["OLD", "NEW"], conflicts_with_all = ["stdin", "capabilities", "attestation"])]
pub diff: Vec<String>,
#[arg(long)]
pub gate: bool,
#[arg(long, requires_all = ["crate_name", "crate_version"])]
pub attestation: bool,
#[arg(long, value_name = "NAME")]
pub crate_name: Option<String>,
#[arg(long, value_name = "VERSION")]
pub crate_version: Option<String>,
#[cfg(feature = "semantic")]
#[arg(long)]
pub semantic: bool,
}
impl Cli {
pub fn to_check_config(&self, file_config: Option<&ConfigFile>) -> CheckConfig {
let mut base = file_config.map_or_else(CheckConfig::default, CheckConfig::from_config_file);
base.max_depth = self.max_depth;
base.check_nested_if = base.check_nested_if && !self.no_nested_if;
base.check_if_in_match = base.check_if_in_match && !self.no_if_in_match;
base.check_nested_match = base.check_nested_match && !self.no_nested_match;
base.check_match_in_if = base.check_match_in_if && !self.no_match_in_if;
base.check_else_chain = base.check_else_chain && !self.no_else_chain;
base
}
}