From 92fbaeb8226f96e9704bc4af818ce078641e4834 Mon Sep 17 00:00:00 2001 From: Soof Golan Date: Wed, 21 Aug 2024 17:40:49 +0200 Subject: [PATCH] List all existing tool references on `rye toolchain remove` --- rye/src/cli/toolchain.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/rye/src/cli/toolchain.rs b/rye/src/cli/toolchain.rs index 3e144a2bf7..8081abd5a5 100644 --- a/rye/src/cli/toolchain.rs +++ b/rye/src/cli/toolchain.rs @@ -121,12 +121,28 @@ fn check_in_use(ver: &PythonVersion) -> Result<(), Error> { // Check if used by any tool. let installed_tools = list_installed_tools()?; - for (tool, info) in &installed_tools { - if let Some(ref venv_marker) = info.venv_marker { - if &venv_marker.python == ver { - bail!("toolchain {} is still in use by tool {}", ver, tool); + + let toolchain_refs = installed_tools + .iter() + .filter_map(|(tool, info)| { + if let Some(ref venv_marker) = info.venv_marker { + match &venv_marker.python == ver { + true => Some(tool.clone()), + false => None, + } + } else { + None } - } + }) + .collect::>(); + + if !toolchain_refs.is_empty() { + bail!( + "toolchain {} is still in use by tool{} {}", + ver, + if toolchain_refs.len() > 1 { "s:" } else { "" }, + toolchain_refs.join(", ") + ); } Ok(())