diff --git a/crates/uv/src/commands/clean.rs b/crates/uv/src/commands/cache_clean.rs similarity index 99% rename from crates/uv/src/commands/clean.rs rename to crates/uv/src/commands/cache_clean.rs index a598fbbbb40a..c26c39e7d868 100644 --- a/crates/uv/src/commands/clean.rs +++ b/crates/uv/src/commands/cache_clean.rs @@ -11,7 +11,7 @@ use crate::commands::ExitStatus; use crate::printer::Printer; /// Clear the cache. -pub(crate) fn clean( +pub(crate) fn cache_clean( cache: &Cache, packages: &[PackageName], mut printer: Printer, diff --git a/crates/uv/src/commands/cache_dir.rs b/crates/uv/src/commands/cache_dir.rs new file mode 100644 index 000000000000..c406671afd72 --- /dev/null +++ b/crates/uv/src/commands/cache_dir.rs @@ -0,0 +1,8 @@ +use owo_colors::OwoColorize; +use uv_cache::Cache; +use uv_fs::Normalized; + +/// Show the cache directory. +pub(crate) fn cache_dir(cache: &Cache) { + anstream::println!("{}", cache.root().normalized_display().cyan()); +} diff --git a/crates/uv/src/commands/mod.rs b/crates/uv/src/commands/mod.rs index 37f1814f3034..0634348fa64a 100644 --- a/crates/uv/src/commands/mod.rs +++ b/crates/uv/src/commands/mod.rs @@ -1,18 +1,20 @@ use std::process::ExitCode; use std::time::Duration; -pub(crate) use clean::clean; +pub(crate) use cache_clean::cache_clean; +pub(crate) use cache_dir::cache_dir; use distribution_types::InstalledMetadata; -pub(crate) use freeze::freeze; pub(crate) use pip_compile::{extra_name_with_clap_error, pip_compile, Upgrade}; +pub(crate) use pip_freeze::pip_freeze; pub(crate) use pip_install::pip_install; pub(crate) use pip_sync::pip_sync; pub(crate) use pip_uninstall::pip_uninstall; pub(crate) use venv::venv; -mod clean; -mod freeze; +mod cache_clean; +mod cache_dir; mod pip_compile; +mod pip_freeze; mod pip_install; mod pip_sync; mod pip_uninstall; diff --git a/crates/uv/src/commands/freeze.rs b/crates/uv/src/commands/pip_freeze.rs similarity index 93% rename from crates/uv/src/commands/freeze.rs rename to crates/uv/src/commands/pip_freeze.rs index 0899ea247fd4..28750fd1464a 100644 --- a/crates/uv/src/commands/freeze.rs +++ b/crates/uv/src/commands/pip_freeze.rs @@ -17,7 +17,7 @@ use crate::commands::ExitStatus; use crate::printer::Printer; /// Enumerate the installed packages in the current environment. -pub(crate) fn freeze(cache: &Cache, strict: bool, mut printer: Printer) -> Result { +pub(crate) fn pip_freeze(cache: &Cache, strict: bool, mut printer: Printer) -> Result { // Detect the current Python interpreter. let platform = Platform::current()?; let venv = Virtualenv::from_env(platform, cache)?; diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 331ef0c03a1b..b99cc0693ea6 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -117,7 +117,7 @@ enum Commands { Venv(VenvArgs), /// Manage the cache. Cache(CacheNamespace), - /// Clear the cache. + /// Remove all items from the cache. #[clap(hide = true)] Clean(CleanArgs), /// Generate shell completion @@ -133,8 +133,24 @@ struct CacheNamespace { #[derive(Subcommand)] enum CacheCommand { - /// Clear the cache. + /// Remove all items from the cache. Clean(CleanArgs), + /// Show the cache directory. + Dir, +} + +#[derive(Args)] +#[allow(clippy::struct_excessive_bools)] +struct CleanArgs { + /// The packages to remove from the cache. + package: Vec, +} + +#[derive(Args)] +#[allow(clippy::struct_excessive_bools)] +struct DirArgs { + /// The packages to remove from the cache. + package: Vec, } #[derive(Args)] @@ -640,13 +656,6 @@ struct PipFreezeArgs { strict: bool, } -#[derive(Args)] -#[allow(clippy::struct_excessive_bools)] -struct CleanArgs { - /// The packages to remove from the cache. - package: Vec, -} - #[derive(Args)] #[allow(clippy::struct_excessive_bools)] struct VenvArgs { @@ -1033,11 +1042,17 @@ async fn run() -> Result { } Commands::Pip(PipNamespace { command: PipCommand::Freeze(args), - }) => commands::freeze(&cache, args.strict, printer), + }) => commands::pip_freeze(&cache, args.strict, printer), Commands::Cache(CacheNamespace { command: CacheCommand::Clean(args), }) - | Commands::Clean(args) => commands::clean(&cache, &args.package, printer), + | Commands::Clean(args) => commands::cache_clean(&cache, &args.package, printer), + Commands::Cache(CacheNamespace { + command: CacheCommand::Dir, + }) => { + commands::cache_dir(&cache); + Ok(ExitStatus::Success) + } Commands::Venv(args) => { args.compat_args.validate()?;