Skip to main content

zoi_cli/cmd/
clean.rs

1//! Command for cleaning the package cache.
2
3use anyhow::Result;
4use colored::Colorize;
5
6use crate::pkg;
7
8/// Runs the clean command.
9///
10/// # Errors
11///
12/// Returns an error if the cache clearing operation fails.
13///
14/// # Panics
15///
16/// This function does not explicitly panic.
17pub fn run(dry_run: bool) -> Result<()> {
18    if dry_run {
19        println!("{} Cleaning cache (Dry-run)...", "::".bold().yellow());
20    } else {
21        println!("{} Cleaning cache...", "::".bold().blue());
22    }
23    pkg::cache::clear(dry_run)?;
24    pkg::cache::clear_archives(dry_run)?;
25    if !dry_run {
26        println!("{}", "Cache cleaned successfully.".green());
27    }
28    Ok(())
29}