Skip to content

Commit d39d095

Browse files
committed
Add cache subcommand
Signed-off-by: innocentzero <[email protected]>
1 parent f2b28be commit d39d095

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/backends/all.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ macro_rules! any {
4040
$($upper_backend,)*
4141
}
4242
impl AnyBackend {
43+
pub fn clean_cache(&self, config: &Config) -> Result<()> {
44+
match self {
45+
$( AnyBackend::$upper_backend => $upper_backend::clean_cache(config), )*
46+
}
47+
}
4348
pub fn version(&self, config: &Config) -> Result<String> {
4449
match self {
4550
$( AnyBackend::$upper_backend => $upper_backend::version(config), )*

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum MainSubcommand {
3131
Sync(SyncCommand),
3232
Unmanaged(UnmanagedCommand),
3333
Backends(BackendsCommand),
34+
Cache(CacheCommand),
3435
}
3536

3637
#[derive(Args)]
@@ -86,3 +87,10 @@ pub struct UnmanagedCommand {}
8687
#[command(visible_alias("b"))]
8788
/// show the backends found by metapac
8889
pub struct BackendsCommand {}
90+
91+
#[derive(Args)]
92+
/// Clean the cache of all the backends, or the ones specified
93+
pub struct CacheCommand {
94+
#[arg(short, long)]
95+
pub backends: Option<Vec<String>>,
96+
}

src/core.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dialoguer::Confirm;
77
use strum::IntoEnumIterator;
88
use toml_edit::{Array, DocumentMut, Item, Value};
99

10-
use crate::cli::BackendsCommand;
10+
use crate::cli::{BackendsCommand, CacheCommand};
1111
use crate::prelude::*;
1212
use crate::review::review;
1313

@@ -44,6 +44,7 @@ impl MainArguments {
4444
MainSubcommand::Sync(sync) => sync.run(&managed, &config),
4545
MainSubcommand::Unmanaged(unmanaged) => unmanaged.run(&managed, &config),
4646
MainSubcommand::Backends(found_backends) => found_backends.run(&config),
47+
MainSubcommand::Cache(backends) => backends.run(&config),
4748
}
4849
}
4950
}
@@ -190,6 +191,17 @@ impl BackendsCommand {
190191
}
191192
}
192193

194+
impl CacheCommand {
195+
fn run(&self, config: &Config) -> Result<()> {
196+
for backend in AnyBackend::iter() {
197+
println!("Cleaning cache for {backend}\n\n");
198+
backend.clean_cache(config)?
199+
}
200+
println!("\n\nCleaned all available backends");
201+
Ok(())
202+
}
203+
}
204+
193205
fn unmanaged(managed: &InstallOptions, config: &Config) -> Result<PackageIds> {
194206
QueryInfos::query_installed_packages(config)
195207
.map(|x| x.to_package_ids().difference(&managed.to_package_ids()))

0 commit comments

Comments
 (0)