diff --git a/crates/uv/src/commands/tool/run.rs b/crates/uv/src/commands/tool/run.rs index 2ff7dd321d76..9ee839e97975 100644 --- a/crates/uv/src/commands/tool/run.rs +++ b/crates/uv/src/commands/tool/run.rs @@ -158,7 +158,17 @@ pub(crate) async fn run( "The executable `{}` was not found.", executable.to_string_lossy().cyan(), )?; - if !entrypoints.is_empty() { + if entrypoints.is_empty() { + warn_user!( + "Package `{}` does not provide any executables.", + from.name.red() + ); + } else { + warn_user!( + "An executable named `{}` is not provided by package `{}`.", + executable.to_string_lossy().cyan(), + from.name.red() + ); writeln!( printer.stdout(), "The following executables are provided by `{}`:", @@ -230,13 +240,7 @@ fn warn_executable_not_provided_by_package( .any(|package| package.name() == from_package) { match packages.as_slice() { - [] => { - warn_user!( - "An executable named `{}` is not provided by package `{}`.", - executable.cyan(), - from_package.red() - ); - } + [] => {} [package] => { let suggested_command = format!( "{invocation_source} --from {} {}", diff --git a/crates/uv/tests/tool_run.rs b/crates/uv/tests/tool_run.rs index 35f52dd11b0a..e63a32c38769 100644 --- a/crates/uv/tests/tool_run.rs +++ b/crates/uv/tests/tool_run.rs @@ -247,7 +247,7 @@ fn tool_run_suggest_valid_commands() { + fastapi-cli==0.0.1 + importlib-metadata==1.7.0 + zipp==3.18.1 - warning: An executable named `fastapi-cli` is not provided by package `fastapi-cli`. + warning: Package `fastapi-cli` does not provide any executables. "###); } @@ -835,3 +835,32 @@ fn tool_run_without_output() { warning: `uv tool run` is experimental and may change without warning "###); } + +#[test] +fn warn_no_executables_found() { + let context = TestContext::new("3.12").with_filtered_exe_suffix(); + let tool_dir = context.temp_dir.child("tools"); + let bin_dir = context.temp_dir.child("bin"); + + uv_snapshot!(context.filters(), context.tool_run() + .arg("requests") + .env("UV_TOOL_DIR", tool_dir.as_os_str()) + .env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" + success: false + exit_code: 1 + ----- stdout ----- + The executable `requests` was not found. + + ----- stderr ----- + warning: `uv tool run` is experimental and may change without warning + Resolved 5 packages in [TIME] + Prepared 5 packages in [TIME] + Installed 5 packages in [TIME] + + certifi==2024.2.2 + + charset-normalizer==3.3.2 + + idna==3.6 + + requests==2.31.0 + + urllib3==2.2.1 + warning: Package `requests` does not provide any executables. + "###); +}