cleanux 0.1.1

Linux cleaner CLI (CleanMyMac-like): scan & safely trash cache, find duplicates, list large files
Documentation
use crate::cleaners::{Cleaner, ScanContext, item_from_path};
use crate::model::{CleanerGroup, Plan};
use anyhow::Result;
use std::path::Path;

pub struct ChromiumCacheCleaner;

impl ChromiumCacheCleaner {
    pub fn new() -> Self {
        Self
    }
}

impl Cleaner for ChromiumCacheCleaner {
    fn id(&self) -> &'static str {
        "chromium_cache"
    }

    fn description(&self) -> &'static str {
        "Chromium-based browser caches under XDG cache"
    }

    fn group(&self) -> CleanerGroup {
        CleanerGroup::Browser
    }

    fn scan(&self, ctx: &ScanContext) -> Result<Plan> {
        let cache_dir = ctx.base_dirs.cache_dir();
        let candidates = [
            "chromium",
            "google-chrome",
            "google-chrome-beta",
            "google-chrome-unstable",
            "brave",
            "brave-browser",
            "vivaldi",
            "opera",
            "microsoft-edge",
            "microsoft-edge-beta",
            "microsoft-edge-dev",
        ];

        let mut items = Vec::new();
        for name in candidates {
            let p = cache_dir.join(name);
            if let Some(item) = item_from_path(
                &p,
                self.id(),
                self.group(),
                Some("Browser cache"),
                &ctx.filter,
            )? {
                items.push(item);
            }
        }

        Ok(Plan::new(items))
    }
}

pub struct FirefoxCacheCleaner;

impl FirefoxCacheCleaner {
    pub fn new() -> Self {
        Self
    }
}

impl Cleaner for FirefoxCacheCleaner {
    fn id(&self) -> &'static str {
        "firefox_cache"
    }

    fn description(&self) -> &'static str {
        "Firefox caches under XDG cache"
    }

    fn group(&self) -> CleanerGroup {
        CleanerGroup::Browser
    }

    fn scan(&self, ctx: &ScanContext) -> Result<Plan> {
        let cache_dir = ctx.base_dirs.cache_dir();
        let path = cache_dir.join(Path::new("mozilla/firefox"));

        let mut items = Vec::new();
        if let Some(item) = item_from_path(
            &path,
            self.id(),
            self.group(),
            Some("Browser cache"),
            &ctx.filter,
        )? {
            items.push(item);
        }

        Ok(Plan::new(items))
    }
}