rskiller 0.1.2

Find and clean Rust project build artifacts and caches
Documentation
use anyhow::Result;
use rskiller::{ProjectScanner, Cli, SortBy, Color, utils};
use std::path::PathBuf;

/// Example: Analyze and clean projects programmatically
#[tokio::main]
async fn main() -> Result<()> {
    let cli = Cli {
        directory: PathBuf::from("."),
        full: false,
        target: "target".to_string(),
        sort: SortBy::Size,
        gb: false,
        exclude: None,
        exclude_hidden: false,
        hide_errors: false,
        delete_all: false,
        dry_run: true, // Safe mode - won't actually delete
        list_only: true,
        include_cargo_cache: false,
        color: Color::Blue,
        no_check_update: false,
    };
    
    let scanner = ProjectScanner::new(cli);
    let projects = scanner.scan().await?;
    
    let mut total_cleanable = 0u64;
    let mut stale_projects = Vec::new();
    
    for project in &projects {
        let size = project.total_cleanable_size();
        total_cleanable += size;
        
        // Find projects that haven't been modified in over 30 days
        if !project.is_likely_active() && size > 100 * 1024 * 1024 { // > 100MB
            stale_projects.push(project);
        }
    }
    
    println!("Analysis Results:");
    println!("  Total projects: {}", projects.len());
    println!("  Total cleanable space: {}", utils::format_size(total_cleanable, false));
    println!("  Stale projects (>100MB, >30 days old): {}", stale_projects.len());
    
    if !stale_projects.is_empty() {
        println!("\nStale projects that could be cleaned:");
        for project in &stale_projects {
            println!(
                "  {} - {} - {} days old",
                project.name,
                utils::format_size(project.total_cleanable_size(), false),
                project.days_since_modified().unwrap_or(0)
            );
            
            // In a real scenario, you could clean these:
            // if let Some(target_dir) = &project.target_dir {
            //     utils::remove_directory(target_dir, false)?; // false = actually delete
            // }
        }
    }
    
    Ok(())
}