Skip to content

Commit

Permalink
Accept vec of packages in uv tool uninstall (#7077)
Browse files Browse the repository at this point in the history
## Summary

Follow up
#7037 (comment)

## Test Plan

`cargo test`
  • Loading branch information
blueraft committed Sep 5, 2024
1 parent 316f683 commit 567e213
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,7 @@ pub struct ToolDirArgs {
pub struct ToolUninstallArgs {
/// The name of the tool to uninstall.
#[arg(required = true)]
pub name: Option<Vec<PackageName>>,
pub name: Vec<PackageName>,

/// Uninstall all tools.
#[arg(long, conflicts_with("name"))]
Expand Down
27 changes: 12 additions & 15 deletions crates/uv/src/commands/tool/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

/// Uninstall a tool.
pub(crate) async fn uninstall(
name: Option<Vec<PackageName>>,
printer: Printer,
) -> Result<ExitStatus> {
pub(crate) async fn uninstall(name: Vec<PackageName>, printer: Printer) -> Result<ExitStatus> {
let installed_tools = InstalledTools::from_settings()?.init()?;
let _lock = match installed_tools.lock().await {
Ok(lock) => lock,
Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
if let Some(names) = name {
for name in names {
if !name.is_empty() {
for name in name {
writeln!(printer.stderr(), "`{name}` is not installed")?;
}
return Ok(ExitStatus::Success);
Expand Down Expand Up @@ -94,22 +91,23 @@ impl IgnoreCurrentlyBeingDeleted for Result<(), std::io::Error> {
/// Perform the uninstallation.
async fn do_uninstall(
installed_tools: &InstalledTools,
names: Option<Vec<PackageName>>,
names: Vec<PackageName>,
printer: Printer,
) -> Result<()> {
let mut dangling = false;
let mut entrypoints = if let Some(names) = names {
let mut entrypoints = if names.is_empty() {
let mut entrypoints = vec![];
for name in names {
let Some(receipt) = installed_tools.get_tool_receipt(&name)? else {
for (name, receipt) in installed_tools.tools()? {
let Ok(receipt) = receipt else {
// If the tool is not installed properly, attempt to remove the environment anyway.
match installed_tools.remove_environment(&name) {
Ok(()) => {
dangling = true;
writeln!(
printer.stderr(),
"Removed dangling environment for `{name}`"
)?;
return Ok(());
continue;
}
Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
bail!("`{name}` is not installed");
Expand All @@ -125,17 +123,16 @@ async fn do_uninstall(
entrypoints
} else {
let mut entrypoints = vec![];
for (name, receipt) in installed_tools.tools()? {
let Ok(receipt) = receipt else {
for name in names {
let Some(receipt) = installed_tools.get_tool_receipt(&name)? else {
// If the tool is not installed properly, attempt to remove the environment anyway.
match installed_tools.remove_environment(&name) {
Ok(()) => {
dangling = true;
writeln!(
printer.stderr(),
"Removed dangling environment for `{name}`"
)?;
continue;
return Ok(());
}
Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
bail!("`{name}` is not installed");
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl ToolListSettings {
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)]
pub(crate) struct ToolUninstallSettings {
pub(crate) name: Option<Vec<PackageName>>,
pub(crate) name: Vec<PackageName>,
}

impl ToolUninstallSettings {
Expand All @@ -492,7 +492,7 @@ impl ToolUninstallSettings {
let ToolUninstallArgs { name, all } = args;

Self {
name: name.filter(|_| !all),
name: if all { vec![] } else { name },
}
}
}
Expand Down

0 comments on commit 567e213

Please sign in to comment.