Skip to content

Commit

Permalink
Make the context message more informative
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Sep 24, 2024
1 parent 5cf16d0 commit a0cc8ad
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
14 changes: 11 additions & 3 deletions crates/uv/src/commands/tool/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ pub(crate) async fn list(
printer: Printer,
) -> Result<ExitStatus> {
let installed_tools = InstalledTools::from_settings()?;
let no_tools_installed_msg =
"No tools installed.\n\nSee `uv tool install --help` for more information.";
let _lock = match installed_tools.lock().await {
Ok(lock) => lock,
Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
writeln!(printer.stderr(), "No tools installed")?;
writeln!(printer.stderr(), "{no_tools_installed_msg}")?;
return Ok(ExitStatus::Success);
}
Err(err) => return Err(err.into()),
Expand All @@ -33,10 +35,16 @@ pub(crate) async fn list(
tools.sort_by_key(|(name, _)| name.clone());

if tools.is_empty() {
writeln!(printer.stderr(), "No tools installed")?;
writeln!(printer.stderr(), "{no_tools_installed_msg}")?;
return Ok(ExitStatus::Success);
}

writeln!(
printer.stdout(),
"Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.\n\n\
The following tools are already installed:\n"
)?;

for (name, tool) in tools {
// Skip invalid tools
let Ok(tool) = tool else {
Expand Down Expand Up @@ -69,7 +77,6 @@ pub(crate) async fn list(
String::new()
};

writeln!(printer.stdout(), "Installed tools:\n")?;
if show_paths {
writeln!(
printer.stdout(),
Expand Down Expand Up @@ -100,5 +107,6 @@ pub(crate) async fn list(
}
}

writeln!(printer.stdout(), "\nSee `uvx --help` for more information.")?;
Ok(ExitStatus::Success)
}
52 changes: 45 additions & 7 deletions crates/uv/tests/tool_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ fn tool_list() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0
- black
- blackd
See `uvx --help` for more information.
----- stderr -----
"###);
}
Expand All @@ -61,12 +65,16 @@ fn tool_list_paths() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0 ([TEMP_DIR]/tools/black)
- black ([TEMP_DIR]/bin/black)
- blackd ([TEMP_DIR]/bin/blackd)
See `uvx --help` for more information.
----- stderr -----
"###);
}
Expand All @@ -85,7 +93,9 @@ fn tool_list_empty() {
----- stdout -----
----- stderr -----
No tools installed
No tools installed.
See `uv tool install --help` for more information.
"###);
}

Expand All @@ -112,6 +122,12 @@ fn tool_list_missing_receipt() {
success: true
exit_code: 0
----- stdout -----
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
See `uvx --help` for more information.
----- stderr -----
warning: Ignoring malformed tool `black` (run `uv tool uninstall black` to remove)
Expand Down Expand Up @@ -159,11 +175,15 @@ fn tool_list_bad_environment() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
ruff v0.3.4
- ruff
See `uvx --help` for more information.
----- stderr -----
Invalid environment at `tools/black`: missing Python executable at `tools/black/[BIN]/python`
"###
Expand Down Expand Up @@ -224,12 +244,16 @@ fn tool_list_deprecated() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0
- black
- blackd
See `uvx --help` for more information.
----- stderr -----
"###);

Expand All @@ -253,6 +277,12 @@ fn tool_list_deprecated() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
See `uvx --help` for more information.
----- stderr -----
warning: Ignoring malformed tool `black` (run `uv tool uninstall black` to remove)
Expand Down Expand Up @@ -282,12 +312,16 @@ fn tool_list_show_version_specifiers() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0 [required: <24.3.0]
- black
- blackd
See `uvx --help` for more information.
----- stderr -----
"###);

Expand All @@ -298,12 +332,16 @@ fn tool_list_show_version_specifiers() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0 [required: <24.3.0] ([TEMP_DIR]/tools/black)
- black ([TEMP_DIR]/bin/black)
- blackd ([TEMP_DIR]/bin/blackd)
See `uvx --help` for more information.
----- stderr -----
"###);
}
10 changes: 8 additions & 2 deletions crates/uv/tests/tool_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ fn tool_run_list_installed() {
----- stdout -----
----- stderr -----
No tools installed
No tools installed.
See `uv tool install --help` for more information.
"###);

// Install `black`.
Expand All @@ -774,12 +776,16 @@ fn tool_run_list_installed() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.
The following tools are already installed:
black v24.2.0
- black
- blackd
See `uvx --help` for more information.
----- stderr -----
"###);
}
Expand Down
8 changes: 6 additions & 2 deletions crates/uv/tests/tool_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ fn tool_uninstall() {
----- stdout -----
----- stderr -----
No tools installed
No tools installed.
See `uv tool install --help` for more information.
"###);

// After uninstalling the tool, we should be able to reinstall it.
Expand Down Expand Up @@ -111,7 +113,9 @@ fn tool_uninstall_multiple_names() {
----- stdout -----
----- stderr -----
No tools installed
No tools installed.
See `uv tool install --help` for more information.
"###);
}

Expand Down

0 comments on commit a0cc8ad

Please sign in to comment.