diff --git a/Cargo.lock b/Cargo.lock index e387b1c91..926f97b7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1670,6 +1670,7 @@ name = "puffin-cli" version = "0.1.0" dependencies = [ "anyhow", + "cacache", "clap", "colored", "directories", diff --git a/Cargo.toml b/Cargo.toml index fc9c734a2..7129ba7aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ license = "MIT OR Apache-2.0" [workspace.dependencies] anyhow = { version = "1.0.75" } bitflags = { version = "2.4.0" } +cacache = { version = "11.7.1", default-features = false, features = ["tokio-runtime"] } clap = { version = "4.4.6" } colored = { version = "2.0.4" } configparser = { version = "3.0.2" } diff --git a/crates/puffin-cli/Cargo.toml b/crates/puffin-cli/Cargo.toml index 43eb00333..ca4425278 100644 --- a/crates/puffin-cli/Cargo.toml +++ b/crates/puffin-cli/Cargo.toml @@ -15,6 +15,7 @@ platform-host = { path = "../platform-host" } puffin-resolver = { path = "../puffin-resolver" } anyhow = { workspace = true } +cacache = { workspace = true } clap = { workspace = true, features = ["derive"] } colored = { workspace = true } directories = { workspace = true } diff --git a/crates/puffin-cli/src/commands/clean.rs b/crates/puffin-cli/src/commands/clean.rs new file mode 100644 index 000000000..c81a3aaad --- /dev/null +++ b/crates/puffin-cli/src/commands/clean.rs @@ -0,0 +1,17 @@ +use std::path::Path; + +use anyhow::Result; +use tracing::info; + +use crate::commands::ExitStatus; + +/// Clear the cache. +pub(crate) async fn clean(cache: Option<&Path>) -> Result { + let Some(cache) = cache else { + return Err(anyhow::anyhow!("No cache found")); + }; + + info!("Clearing cache at {}", cache.display()); + cacache::clear(cache).await?; + Ok(ExitStatus::Success) +} diff --git a/crates/puffin-cli/src/commands/mod.rs b/crates/puffin-cli/src/commands/mod.rs index 0a1872a0b..f0383fa06 100644 --- a/crates/puffin-cli/src/commands/mod.rs +++ b/crates/puffin-cli/src/commands/mod.rs @@ -1,8 +1,10 @@ use std::process::ExitCode; +pub(crate) use clean::clean; pub(crate) use compile::compile; pub(crate) use sync::sync; +mod clean; mod compile; mod sync; diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index 37db96f80..a72954b6f 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -24,6 +24,8 @@ enum Commands { Compile(CompileArgs), /// Sync dependencies from a `requirements.txt` file. Sync(SyncArgs), + /// Clear the cache. + Clean, } #[derive(Args)] @@ -73,6 +75,7 @@ async fn main() -> ExitCode { ) .await } + Commands::Clean => commands::clean(dirs.as_ref().map(ProjectDirs::cache_dir)).await, }; match result { diff --git a/crates/puffin-installer/Cargo.toml b/crates/puffin-installer/Cargo.toml index 51afe3839..c87ac459c 100644 --- a/crates/puffin-installer/Cargo.toml +++ b/crates/puffin-installer/Cargo.toml @@ -16,9 +16,9 @@ puffin-interpreter = { path = "../puffin-interpreter" } wheel-filename = { path = "../wheel-filename" } anyhow = { workspace = true } +cacache = { workspace = true } tempfile = { workspace = true } -tracing = { workspace = true } -url = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } -cacache = { version = "11.7.1", default-features = false, features = ["tokio-runtime"] } +tracing = { workspace = true } +url = { workspace = true }