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 23, 2024
1 parent 7471018 commit dcf1254
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 34 deletions.
18 changes: 13 additions & 5 deletions crates/uv/src/commands/tool/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,26 @@ pub(crate) async fn list(
String::new()
};

writeln!(printer.stdout(), "Installed tools:\n")?;
writeln!(
printer.stdout(),
"Provide a tool to invoke with `uvx <name>`.\n\
e.g. `uvx ruff`\n\
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.\n\
e.g. `uvx --from black blackd`\n\
The following tools (and executables) are already installed:\n\
"
)?;
if show_paths {
writeln!(
printer.stdout(),
"{} ({})",
"- {} ({})",
format!("{name} v{version}{version_specifier}").bold(),
installed_tools.tool_dir(&name).simplified_display().cyan(),
)?;
} else {
writeln!(
printer.stdout(),
"{}",
"- {}",
format!("{name} v{version}{version_specifier}").bold()
)?;
}
Expand All @@ -90,12 +98,12 @@ pub(crate) async fn list(
if show_paths {
writeln!(
printer.stdout(),
"- {} ({})",
" * {} ({})",
entrypoint.name,
entrypoint.install_path.simplified_display().cyan()
)?;
} else {
writeln!(printer.stdout(), "- {}", entrypoint.name)?;
writeln!(printer.stdout(), " * {}", entrypoint.name)?;
}
}
}
Expand Down
72 changes: 48 additions & 24 deletions crates/uv/tests/tool_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ fn tool_list() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
black v24.2.0
- black
- blackd
- black v24.2.0
* black
* blackd
----- stderr -----
"###);
Expand All @@ -61,11 +65,15 @@ fn tool_list_paths() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
black v24.2.0 ([TEMP_DIR]/tools/black)
- black ([TEMP_DIR]/bin/black)
- blackd ([TEMP_DIR]/bin/blackd)
- black v24.2.0 ([TEMP_DIR]/tools/black)
* black ([TEMP_DIR]/bin/black)
* blackd ([TEMP_DIR]/bin/blackd)
----- stderr -----
"###);
Expand Down Expand Up @@ -159,10 +167,14 @@ fn tool_list_bad_environment() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
ruff v0.3.4
- ruff
- ruff v0.3.4
* ruff
----- stderr -----
Invalid environment at `tools/black`: missing Python executable at `tools/black/[BIN]/python`
Expand Down Expand Up @@ -224,11 +236,15 @@ fn tool_list_deprecated() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
black v24.2.0
- black
- blackd
- black v24.2.0
* black
* blackd
----- stderr -----
"###);
Expand Down Expand Up @@ -282,11 +298,15 @@ fn tool_list_show_version_specifiers() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
black v24.2.0 [required: <24.3.0]
- black
- blackd
- black v24.2.0 [required: <24.3.0]
* black
* blackd
----- stderr -----
"###);
Expand All @@ -298,11 +318,15 @@ fn tool_list_show_version_specifiers() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
black v24.2.0 [required: <24.3.0] ([TEMP_DIR]/tools/black)
- black ([TEMP_DIR]/bin/black)
- blackd ([TEMP_DIR]/bin/blackd)
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) 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)
----- stderr -----
"###);
Expand Down
14 changes: 9 additions & 5 deletions crates/uv/tests/tool_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,15 @@ fn tool_run_list_installed() {
success: true
exit_code: 0
----- stdout -----
Installed tools:
black v24.2.0
- black
- blackd
Provide a tool to invoke with `uvx <name>`.
e.g. `uvx ruff`
If the tool provides multiple executables, you can use `uvx --from <name> <executable>`.
e.g. `uvx --from black blackd`
The following tools (and executables) are already installed:
- black v24.2.0
* black
* blackd
----- stderr -----
"###);
Expand Down

0 comments on commit dcf1254

Please sign in to comment.