diff --git a/crates/uv/src/commands/auth/dir.rs b/crates/uv/src/commands/auth/dir.rs index 0d30d41c0..04317b278 100644 --- a/crates/uv/src/commands/auth/dir.rs +++ b/crates/uv/src/commands/auth/dir.rs @@ -1,20 +1,26 @@ -use anstream::println; use owo_colors::OwoColorize; +use std::fmt::Write; use uv_auth::{PyxTokenStore, Service, TextCredentialStore}; use uv_fs::Simplified; +use crate::printer::Printer; + /// Show the credentials directory. -pub(crate) fn dir(service: Option<&Service>) -> anyhow::Result<()> { +pub(crate) fn dir(service: Option<&Service>, printer: Printer) -> anyhow::Result<()> { if let Some(service) = service { let pyx_store = PyxTokenStore::from_settings()?; if pyx_store.is_known_domain(service.url()) { - println!("{}", pyx_store.root().simplified_display().cyan()); + writeln!( + printer.stdout(), + "{}", + pyx_store.root().simplified_display().cyan() + )?; return Ok(()); } } let root = TextCredentialStore::directory_path()?; - println!("{}", root.simplified_display().cyan()); + writeln!(printer.stdout(), "{}", root.simplified_display().cyan())?; Ok(()) } diff --git a/crates/uv/src/commands/cache_dir.rs b/crates/uv/src/commands/cache_dir.rs index b028003e5..a5a3bdcdc 100644 --- a/crates/uv/src/commands/cache_dir.rs +++ b/crates/uv/src/commands/cache_dir.rs @@ -1,10 +1,18 @@ -use anstream::println; use owo_colors::OwoColorize; +use std::fmt::Write; use uv_cache::Cache; use uv_fs::Simplified; +use crate::commands::ExitStatus; +use crate::printer::Printer; + /// Show the cache directory. -pub(crate) fn cache_dir(cache: &Cache) { - println!("{}", cache.root().simplified_display().cyan()); +pub(crate) fn cache_dir(cache: &Cache, printer: Printer) -> anyhow::Result { + writeln!( + printer.stdout(), + "{}", + cache.root().simplified_display().cyan() + )?; + Ok(ExitStatus::Success) } diff --git a/crates/uv/src/commands/python/dir.rs b/crates/uv/src/commands/python/dir.rs index 3c3f71172..22188e5d5 100644 --- a/crates/uv/src/commands/python/dir.rs +++ b/crates/uv/src/commands/python/dir.rs @@ -1,22 +1,26 @@ -use anstream::println; +use std::fmt::Write; + use anyhow::Context; use owo_colors::OwoColorize; use uv_fs::Simplified; use uv_python::managed::{ManagedPythonInstallations, python_executable_dir}; +use crate::printer::Printer; + /// Show the Python installation directory. -pub(crate) fn dir(bin: bool) -> anyhow::Result<()> { +pub(crate) fn dir(bin: bool, printer: Printer) -> anyhow::Result<()> { if bin { let bin = python_executable_dir()?; - println!("{}", bin.simplified_display().cyan()); + writeln!(printer.stdout(), "{}", bin.simplified_display().cyan())?; } else { let installed_toolchains = ManagedPythonInstallations::from_settings(None) .context("Failed to initialize toolchain settings")?; - println!( + writeln!( + printer.stdout(), "{}", installed_toolchains.root().simplified_display().cyan() - ); + )?; } Ok(()) diff --git a/crates/uv/src/commands/tool/dir.rs b/crates/uv/src/commands/tool/dir.rs index d08f27199..bffcdae83 100644 --- a/crates/uv/src/commands/tool/dir.rs +++ b/crates/uv/src/commands/tool/dir.rs @@ -1,4 +1,5 @@ -use anstream::println; +use std::fmt::Write; + use anyhow::Context; use owo_colors::OwoColorize; @@ -6,15 +7,25 @@ use uv_fs::Simplified; use uv_preview::Preview; use uv_tool::{InstalledTools, tool_executable_dir}; +use crate::printer::Printer; + /// Show the tool directory. -pub(crate) fn dir(bin: bool, _preview: Preview) -> anyhow::Result<()> { +pub(crate) fn dir(bin: bool, _preview: Preview, printer: Printer) -> anyhow::Result<()> { if bin { let executable_directory = tool_executable_dir()?; - println!("{}", executable_directory.simplified_display().cyan()); + writeln!( + printer.stdout(), + "{}", + executable_directory.simplified_display().cyan() + )?; } else { let installed_tools = InstalledTools::from_settings().context("Failed to initialize tools settings")?; - println!("{}", installed_tools.root().simplified_display().cyan()); + writeln!( + printer.stdout(), + "{}", + installed_tools.root().simplified_display().cyan() + )?; } Ok(()) diff --git a/crates/uv/src/commands/workspace/dir.rs b/crates/uv/src/commands/workspace/dir.rs index 1a2fe581f..0372901a5 100644 --- a/crates/uv/src/commands/workspace/dir.rs +++ b/crates/uv/src/commands/workspace/dir.rs @@ -31,11 +31,11 @@ pub(crate) async fn dir( let workspace = Workspace::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache).await?; - let dir: &Path = match package_name { - None => workspace.install_path().as_path(), + let dir = match package_name { + None => workspace.install_path(), Some(package) => { if let Some(p) = workspace.packages().get(&package) { - p.root().as_path() + p.root() } else { bail!("Package `{package}` not found in workspace.") } diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index a13471e1b..bf7bde120 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -531,7 +531,7 @@ async fn run(mut cli: Cli) -> Result { Commands::Auth(AuthNamespace { command: AuthCommand::Dir(args), }) => { - commands::auth_dir(args.service.as_ref())?; + commands::auth_dir(args.service.as_ref(), printer)?; Ok(ExitStatus::Success) } Commands::Help(args) => commands::help( @@ -1056,10 +1056,7 @@ async fn run(mut cli: Cli) -> Result { } Commands::Cache(CacheNamespace { command: CacheCommand::Dir, - }) => { - commands::cache_dir(&cache); - Ok(ExitStatus::Success) - } + }) => commands::cache_dir(&cache, printer), Commands::Cache(CacheNamespace { command: CacheCommand::Size(args), }) => commands::cache_size(&cache, args.human, printer, globals.preview), @@ -1504,7 +1501,7 @@ async fn run(mut cli: Cli) -> Result { let args = settings::ToolDirSettings::resolve(args, filesystem); show_settings!(args); - commands::tool_dir(args.bin, globals.preview)?; + commands::tool_dir(args.bin, globals.preview, printer)?; Ok(ExitStatus::Success) } Commands::Python(PythonNamespace { @@ -1680,7 +1677,7 @@ async fn run(mut cli: Cli) -> Result { let args = settings::PythonDirSettings::resolve(args, filesystem); show_settings!(args); - commands::python_dir(args.bin)?; + commands::python_dir(args.bin, printer)?; Ok(ExitStatus::Success) } Commands::Python(PythonNamespace { diff --git a/crates/uv/tests/it/workspace_dir.rs b/crates/uv/tests/it/workspace_dir.rs index 978dc8394..ac56829b9 100644 --- a/crates/uv/tests/it/workspace_dir.rs +++ b/crates/uv/tests/it/workspace_dir.rs @@ -27,7 +27,7 @@ fn workspace_dir_simple() { ); } -// Workspace dir output when run with `--package` +/// Workspace dir output when run with `--package`. #[test] fn workspace_dir_specific_package() { let context = TestContext::new("3.12");