Add a clean command to clear the cache (#41)

This commit is contained in:
Charlie Marsh 2023-10-07 11:19:03 -04:00 committed by GitHub
parent f14b1f0c95
commit f3015ffc1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 3 deletions

1
Cargo.lock generated
View file

@ -1670,6 +1670,7 @@ name = "puffin-cli"
version = "0.1.0"
dependencies = [
"anyhow",
"cacache",
"clap",
"colored",
"directories",

View file

@ -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" }

View file

@ -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 }

View file

@ -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<ExitStatus> {
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)
}

View file

@ -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;

View file

@ -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 {

View file

@ -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 }