Improve consistency of tool CLI (#5326)

## Summary

More consistent colors, etc.
This commit is contained in:
Charlie Marsh 2024-07-22 23:10:47 -04:00 committed by GitHub
parent 0a6efe4d26
commit e61fcbd7af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 22 deletions

View file

@ -88,7 +88,7 @@ pub(crate) async fn install(
// Parse the positional name. If the user provided more than a package name, it's an error // Parse the positional name. If the user provided more than a package name, it's an error
// (e.g., `uv install foo==1.0 --from foo`). // (e.g., `uv install foo==1.0 --from foo`).
let Ok(package) = PackageName::from_str(&package) else { let Ok(package) = PackageName::from_str(&package) else {
bail!("Package requirement (`{from}`) provided with `--from` conflicts with install request (`{package}`)") bail!("Package requirement (`{from}`) provided with `--from` conflicts with install request (`{package}`)", from = from.cyan(), package = package.cyan())
}; };
let from_requirement = resolve_requirements( let from_requirement = resolve_requirements(
@ -112,8 +112,8 @@ pub(crate) async fn install(
// Determine if it's an entirely different package (e.g., `uv install foo --from bar`). // Determine if it's an entirely different package (e.g., `uv install foo --from bar`).
bail!( bail!(
"Package name (`{}`) provided with `--from` does not match install request (`{}`)", "Package name (`{}`) provided with `--from` does not match install request (`{}`)",
from_requirement.name, from_requirement.name.cyan(),
package package.cyan()
); );
} }
@ -177,7 +177,10 @@ pub(crate) async fn install(
// If the tool is not installed properly, remove the environment and continue. // If the tool is not installed properly, remove the environment and continue.
match installed_tools.remove_environment(&from.name) { match installed_tools.remove_environment(&from.name) {
Ok(()) => { Ok(()) => {
warn_user!("Removed existing `{}` with invalid receipt", from.name); warn_user!(
"Removed existing `{from}` with invalid receipt",
from = from.name.cyan()
);
} }
Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {} Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {}
Err(err) => { Err(err) => {
@ -194,13 +197,13 @@ pub(crate) async fn install(
.filter(|environment| { .filter(|environment| {
python_request.as_ref().map_or(true, |python_request| { python_request.as_ref().map_or(true, |python_request| {
if python_request.satisfied(environment.interpreter(), cache) { if python_request.satisfied(environment.interpreter(), cache) {
debug!("Found existing environment for `{}`", from.name); debug!("Found existing environment for `{from}`", from = from.name.cyan());
true true
} else { } else {
let _ = writeln!( let _ = writeln!(
printer.stderr(), printer.stderr(),
"Existing environment for `{}` does not satisfy the requested Python interpreter", "Existing environment for `{from}` does not satisfy the requested Python interpreter",
from.name, from = from.name.cyan(),
); );
false false
} }
@ -220,7 +223,11 @@ pub(crate) async fn install(
// And the user didn't request a reinstall or upgrade... // And the user didn't request a reinstall or upgrade...
if !force && settings.reinstall.is_none() && settings.upgrade.is_none() { if !force && settings.reinstall.is_none() && settings.upgrade.is_none() {
// We're done. // We're done.
writeln!(printer.stderr(), "`{from}` is already installed")?; writeln!(
printer.stderr(),
"`{from}` is already installed",
from = from.cyan()
)?;
return Ok(ExitStatus::Success); return Ok(ExitStatus::Success);
} }
} }
@ -324,8 +331,8 @@ pub(crate) async fn install(
if target_entry_points.is_empty() { if target_entry_points.is_empty() {
writeln!( writeln!(
printer.stdout(), printer.stdout(),
"No executables are provided by package `{}`.", "No executables are provided by `{from}`",
from.name.red() from = from.name.cyan()
)?; )?;
hint_executable_from_dependency(&from, &environment, printer)?; hint_executable_from_dependency(&from, &environment, printer)?;
@ -412,13 +419,13 @@ pub(crate) async fn install(
if let Some(command) = shell.prepend_path(&executable_directory) { if let Some(command) = shell.prepend_path(&executable_directory) {
if shell.configuration_files().is_empty() { if shell.configuration_files().is_empty() {
warn_user!( warn_user!(
"{} is not on your PATH. To use installed tools, run {}.", "`{}` is not on your PATH. To use installed tools, run `{}`.",
executable_directory.simplified_display().cyan(), executable_directory.simplified_display().cyan(),
command.green() command.green()
); );
} else { } else {
warn_user!( warn_user!(
"{} is not on your PATH. To use installed tools, run {} or {}.", "`{}` is not on your PATH. To use installed tools, run `{}` or `{}`.",
executable_directory.simplified_display().cyan(), executable_directory.simplified_display().cyan(),
command.green(), command.green(),
"uv tool update-shell".green() "uv tool update-shell".green()
@ -426,13 +433,13 @@ pub(crate) async fn install(
} }
} else { } else {
warn_user!( warn_user!(
"{} is not on your PATH. To use installed tools, add the directory to your PATH.", "`{}` is not on your PATH. To use installed tools, add the directory to your PATH.",
executable_directory.simplified_display().cyan(), executable_directory.simplified_display().cyan(),
); );
} }
} else { } else {
warn_user!( warn_user!(
"{} is not on your PATH. To use installed tools, add the directory to your PATH.", "`{}` is not on your PATH. To use installed tools, add the directory to your PATH.",
executable_directory.simplified_display().cyan(), executable_directory.simplified_display().cyan(),
); );
} }
@ -455,8 +462,8 @@ fn hint_executable_from_dependency(
writeln!( writeln!(
printer.stdout(), printer.stdout(),
"However, an executable with the name `{}` is available via dependency `{}`.\nDid you mean `{}`?", "However, an executable with the name `{}` is available via dependency `{}`.\nDid you mean `{}`?",
from.name.green(), from.name.cyan(),
package.name().green(), package.name().cyan(),
command.bold(), command.bold(),
)?; )?;
} }
@ -464,7 +471,7 @@ fn hint_executable_from_dependency(
writeln!( writeln!(
printer.stdout(), printer.stdout(),
"However, an executable with the name `{}` is available via the following dependencies::", "However, an executable with the name `{}` is available via the following dependencies::",
from.name.green(), from.name.cyan(),
)?; )?;
for package in packages { for package in packages {

View file

@ -157,13 +157,13 @@ pub(crate) async fn run(
writeln!( writeln!(
printer.stdout(), printer.stdout(),
"The executable `{}` was not found.", "The executable `{}` was not found.",
executable.to_string_lossy().red(), executable.to_string_lossy().cyan(),
)?; )?;
if !entrypoints.is_empty() { if !entrypoints.is_empty() {
writeln!( writeln!(
printer.stdout(), printer.stdout(),
"The following executables are provided by `{}`:", "The following executables are provided by `{}`:",
&from.name.green() from.name.green()
)?; )?;
for (name, _) in entrypoints { for (name, _) in entrypoints {
writeln!(printer.stdout(), "- {}", name.cyan())?; writeln!(printer.stdout(), "- {}", name.cyan())?;

View file

@ -188,7 +188,7 @@ fn tool_install_suggest_other_packages_with_executable() {
success: false success: false
exit_code: 1 exit_code: 1
----- stdout ----- ----- stdout -----
No executables are provided by package `fastapi`. No executables are provided by `fastapi`
However, an executable with the name `fastapi` is available via dependency `fastapi-cli`. However, an executable with the name `fastapi` is available via dependency `fastapi-cli`.
Did you mean `uv tool install fastapi-cli`? Did you mean `uv tool install fastapi-cli`?
@ -976,7 +976,7 @@ fn tool_install_no_entrypoints() {
success: false success: false
exit_code: 1 exit_code: 1
----- stdout ----- ----- stdout -----
No executables are provided by package `iniconfig`. No executables are provided by `iniconfig`
----- stderr ----- ----- stderr -----
warning: `uv tool install` is experimental and may change without warning warning: `uv tool install` is experimental and may change without warning
@ -1606,7 +1606,7 @@ fn tool_install_warn_path() {
+ pathspec==0.12.1 + pathspec==0.12.1
+ platformdirs==4.2.0 + platformdirs==4.2.0
Installed 2 executables: black, blackd Installed 2 executables: black, blackd
warning: [TEMP_DIR]/bin is not on your PATH. To use installed tools, run export PATH="[TEMP_DIR]/bin:$PATH" or uv tool update-shell. warning: `[TEMP_DIR]/bin` is not on your PATH. To use installed tools, run `export PATH="[TEMP_DIR]/bin:$PATH"` or `uv tool update-shell`.
"###); "###);
} }