dl-cleaner 0.1.0

A tool to clean up the contents of your Downloads folder.
Documentation
use clap::Parser;
use std::path::PathBuf;
use anyhow::Result;

use dl_cleaner::scan::{scan_downloads, display_scan_results};
use dl_cleaner::organize::organize_by_extension;

#[derive(Parser, Debug)]
#[command(name = "dl-cleaner")]
#[command(about = "Scan and organize files in your Downloads folder by extension", long_about = None)]
struct Args {
    /// Directory to scan (defaults to ~/Downloads)
    #[arg(short, long)]
    dir: Option<PathBuf>,

    /// Only scan and display results without moving files
    #[arg(long)]
    scan_only: bool,
}

fn main() -> Result<()> {
    let args = Args::parse();

    // Determine the download directory path
    let download_dir = if let Some(dir) = args.dir {
        dir
    } else {
        dirs::download_dir()
            .ok_or_else(|| anyhow::anyhow!("Default Downloads directory not found"))?
    };

    println!("Scanning: {:?}\n", download_dir);

    // Scan the download directory
    let files = scan_downloads(&download_dir)?;

    // Display scan results
    display_scan_results(&files);

    // Exit if --scan-only is specified
    if args.scan_only {
        return Ok(());
    }

    // Organize files by extension
    println!("\nOrganizing files by extension...\n");
    organize_by_extension(&download_dir, &files)?;
    println!("Organization complete.");

    Ok(())
}