pub mod commands;
pub mod output;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use crate::config::ConfidenceLevel;
#[derive(Parser, Debug)]
#[command(
name = "ddd",
version,
about = "Conservative TypeScript dead code detection with transitive analysis and confidence scoring",
long_about = None
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(global = true, default_value = ".")]
pub path: PathBuf,
#[arg(short, long, global = true)]
pub config: Option<PathBuf>,
#[arg(short, long, global = true)]
pub verbose: bool,
#[arg(short, long, global = true)]
pub quiet: bool,
}
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
Init(InitArgs),
Analyze(AnalyzeArgs),
Watch(WatchArgs),
}
#[derive(Parser, Debug, Clone)]
pub struct InitArgs {
#[arg(short, long)]
pub force: bool,
#[arg(long, default_value = "toml")]
pub format: String,
}
#[derive(Parser, Debug, Clone)]
pub struct AnalyzeArgs {
#[arg(short, long, default_value = "table")]
pub format: OutputFormat,
#[arg(long, default_value = "high")]
pub confidence: ConfidenceLevel,
#[arg(long)]
pub show_chains: bool,
#[arg(long)]
pub check: bool,
#[arg(long)]
pub progress: bool,
#[arg(short = 'j', long)]
pub jobs: Option<usize>,
#[arg(long)]
pub include_tests: bool,
}
impl Default for AnalyzeArgs {
fn default() -> Self {
Self {
format: OutputFormat::Table,
confidence: ConfidenceLevel::High,
show_chains: false,
check: false,
progress: false,
jobs: None,
include_tests: false,
}
}
}
#[derive(Parser, Debug, Clone)]
pub struct WatchArgs {
#[arg(long, default_value = "500")]
pub debounce: u64,
#[arg(long)]
pub clear: bool,
}
#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)]
pub enum OutputFormat {
#[default]
Table,
Json,
Compact,
}
impl Cli {
pub fn parse_args() -> Self {
Self::parse()
}
pub fn effective_command(&self) -> Commands {
self.command.clone().unwrap_or(Commands::Analyze(AnalyzeArgs::default()))
}
}
impl From<OutputFormat> for crate::config::OutputFormat {
fn from(f: OutputFormat) -> Self {
match f {
OutputFormat::Table => crate::config::OutputFormat::Table,
OutputFormat::Json => crate::config::OutputFormat::Json,
OutputFormat::Compact => crate::config::OutputFormat::Compact,
}
}
}