loc-rs 0.2.3

Advanced Lines of Code counter with function extraction, git integration, and parallel processing
#![allow(missing_docs)]

// loc — Advanced Lines of Code Counter
//
// Author : kelexine (https://github.com/kelexine)
// Version: See Cargo.toml
// License: MIT
//
// Features:
//   • True data-parallelism via Rayon (all CPU cores)
//   • Zero-copy byte-level line counting
//   • Pre-compiled regex patterns via once_cell::Lazy
//   • Richer function extraction (Rust structs/impls, Python decorators/docstrings)
//   • Filesystem mtime fallback when git is unavailable
//   • walkdir traversal (faster than os.walk)
//   • Typed errors via anyhow — no silent panics

mod cli;
mod config;
mod counter;
mod display;
mod export;
mod extractors;
mod language;
mod models;

use clap::Parser;
use colored::Colorize;
use std::process;

fn main() {
    let mut args = cli::Args::parse();

    // --func-analysis implicitly enables -f
    if args.func_analysis {
        args.functions = true;
    }

    let config = match counter::ScanConfig::from_args(&args) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("{} {}", "[ERROR]".red().bold(), e);
            process::exit(1);
        }
    };

    let result = match counter::run_scan(&config) {
        Ok(r) => r,
        Err(e) => {
            eprintln!("{} {}", "[ERROR]".red().bold(), e);
            process::exit(1);
        }
    };

    // Display tree + summary
    display::display_results(
        &result,
        &config.target_dir,
        args.detailed,
        args.binary,
        args.tree,
        config.warn_size,
        config.extract_functions,
    );

    // Optional function analysis
    if args.func_analysis {
        display::display_function_analysis(&result, &config.target_dir);
    }

    // Optional export
    if let Some(ref output_file) = args.export
        && let Err(e) = export::export(&result, output_file, config.extract_functions)
    {
        eprintln!("{} {}", "[ERROR]".red().bold(), e);
        process::exit(1);
    }
}