use clap::Parser;
use colored::*;
use std::path::PathBuf;
use unused_pub::run;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(default_value = ".")]
path: PathBuf,
#[arg(short, long)]
verbose: bool,
#[arg(short, long)]
filter: Vec<String>,
}
fn main() {
let args = Args::parse();
let start = std::time::Instant::now();
println!("{} {}", "Analyzing".green().bold(), args.path.display());
match run(args.path, args.verbose, args.filter) {
Ok(report) => {
let duration = start.elapsed();
println!("Analysis completed in {:.2?}", duration);
if report.unused_items.is_empty() {
println!("{}", "No unused public items found!".green());
} else {
println!("\n{}", "Unused Public Items:".yellow().bold());
for item in report.unused_items {
println!(
"{} {} ({})",
item.kind.cyan(),
item.name.bold(),
item.location
);
}
println!("\nFound {} unused items.", report.count.to_string().red());
}
}
Err(e) => {
eprintln!("{} {}", "Error:".red().bold(), e);
std::process::exit(1);
}
}
}