diff --git a/src/backends/all.rs b/src/backends/all.rs index 586d13e..221fef4 100644 --- a/src/backends/all.rs +++ b/src/backends/all.rs @@ -40,6 +40,11 @@ macro_rules! any { $($upper_backend,)* } impl AnyBackend { + pub fn clean_cache(&self, config: &Config) -> Result<()> { + match self { + $( AnyBackend::$upper_backend => $upper_backend::clean_cache(config), )* + } + } pub fn version(&self, config: &Config) -> Result { match self { $( AnyBackend::$upper_backend => $upper_backend::version(config), )* diff --git a/src/cli.rs b/src/cli.rs index 72af046..045fdce 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -31,6 +31,7 @@ pub enum MainSubcommand { Sync(SyncCommand), Unmanaged(UnmanagedCommand), Backends(BackendsCommand), + Cache(CacheCommand), } #[derive(Args)] @@ -86,3 +87,10 @@ pub struct UnmanagedCommand {} #[command(visible_alias("b"))] /// show the backends found by metapac pub struct BackendsCommand {} + +#[derive(Args)] +/// Clean the cache of all the backends, or the ones specified +pub struct CacheCommand { + #[arg(short, long)] + pub backends: Option>, +} diff --git a/src/core.rs b/src/core.rs index 860ca9c..80d2ccc 100644 --- a/src/core.rs +++ b/src/core.rs @@ -7,7 +7,7 @@ use dialoguer::Confirm; use strum::IntoEnumIterator; use toml_edit::{Array, DocumentMut, Item, Value}; -use crate::cli::BackendsCommand; +use crate::cli::{BackendsCommand, CacheCommand}; use crate::prelude::*; use crate::review::review; @@ -44,6 +44,7 @@ impl MainArguments { MainSubcommand::Sync(sync) => sync.run(&managed, &config), MainSubcommand::Unmanaged(unmanaged) => unmanaged.run(&managed, &config), MainSubcommand::Backends(found_backends) => found_backends.run(&config), + MainSubcommand::Cache(backends) => backends.run(&config), } } } @@ -190,6 +191,17 @@ impl BackendsCommand { } } +impl CacheCommand { + fn run(&self, config: &Config) -> Result<()> { + for backend in AnyBackend::iter() { + println!("Cleaning cache for {backend}\n\n"); + backend.clean_cache(config)? + } + println!("\n\nCleaned all available backends"); + Ok(()) + } +} + fn unmanaged(managed: &InstallOptions, config: &Config) -> Result { QueryInfos::query_installed_packages(config) .map(|x| x.to_package_ids().difference(&managed.to_package_ids()))