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
// (e.g., `uv install foo==1.0 --from foo`).
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(
@ -112,8 +112,8 @@ pub(crate) async fn install(
// Determine if it's an entirely different package (e.g., `uv install foo --from bar`).
bail!(
"Package name (`{}`) provided with `--from` does not match install request (`{}`)",
from_requirement.name,
package
from_requirement.name.cyan(),
package.cyan()
);
}
@ -177,7 +177,10 @@ pub(crate) async fn install(
// If the tool is not installed properly, remove the environment and continue.
match installed_tools.remove_environment(&from.name) {
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(err) => {
@ -194,13 +197,13 @@ pub(crate) async fn install(
.filter(|environment| {
python_request.as_ref().map_or(true, |python_request| {
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
} else {
let _ = writeln!(
printer.stderr(),
"Existing environment for `{}` does not satisfy the requested Python interpreter",
from.name,
"Existing environment for `{from}` does not satisfy the requested Python interpreter",
from = from.name.cyan(),
);
false
}
@ -220,7 +223,11 @@ pub(crate) async fn install(
// And the user didn't request a reinstall or upgrade...
if !force && settings.reinstall.is_none() && settings.upgrade.is_none() {
// We're done.
writeln!(printer.stderr(), "`{from}` is already installed")?;
writeln!(
printer.stderr(),
"`{from}` is already installed",
from = from.cyan()
)?;
return Ok(ExitStatus::Success);
}
}
@ -324,8 +331,8 @@ pub(crate) async fn install(
if target_entry_points.is_empty() {
writeln!(
printer.stdout(),
"No executables are provided by package `{}`.",
from.name.red()
"No executables are provided by `{from}`",
from = from.name.cyan()
)?;
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 shell.configuration_files().is_empty() {
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(),
command.green()
);
} else {
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(),
command.green(),
"uv tool update-shell".green()
@ -426,13 +433,13 @@ pub(crate) async fn install(
}
} else {
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(),
);
}
} else {
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(),
);
}
@ -455,8 +462,8 @@ fn hint_executable_from_dependency(
writeln!(
printer.stdout(),
"However, an executable with the name `{}` is available via dependency `{}`.\nDid you mean `{}`?",
from.name.green(),
package.name().green(),
from.name.cyan(),
package.name().cyan(),
command.bold(),
)?;
}
@ -464,7 +471,7 @@ fn hint_executable_from_dependency(
writeln!(
printer.stdout(),
"However, an executable with the name `{}` is available via the following dependencies::",
from.name.green(),
from.name.cyan(),
)?;
for package in packages {

View file

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

View file

@ -188,7 +188,7 @@ fn tool_install_suggest_other_packages_with_executable() {
success: false
exit_code: 1
----- 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`.
Did you mean `uv tool install fastapi-cli`?
@ -976,7 +976,7 @@ fn tool_install_no_entrypoints() {
success: false
exit_code: 1
----- stdout -----
No executables are provided by package `iniconfig`.
No executables are provided by `iniconfig`
----- stderr -----
warning: `uv tool install` is experimental and may change without warning
@ -1606,7 +1606,7 @@ fn tool_install_warn_path() {
+ pathspec==0.12.1
+ platformdirs==4.2.0
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`.
"###);
}