Skip to content

Comments

Tweaks to the uvx help menu when no command is provided#7740

Merged
charliermarsh merged 1 commit intomainfrom
zb/tool-help
Sep 27, 2024
Merged

Tweaks to the uvx help menu when no command is provided#7740
charliermarsh merged 1 commit intomainfrom
zb/tool-help

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Sep 27, 2024

Follow-up to #7641 with some minor changes to the implementation and a simplification of the output

@zanieb zanieb added the cli Related to the command line interface label Sep 27, 2024
match list_available_tools(invocation_source, &cache, printer).await {
// It is a failure because user misses a required tool name.
Ok(()) => return Ok(ExitStatus::Error),
Err(err) => return Err(err),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling this case with ? instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, way cleaner 🙈

Comment on lines -282 to -283
let no_tools_installed_msg =
"No tools installed. See `uv tool install --help` for more information.";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After playing with this a bit more, I was worried users would feel like they had to use uv tool install before they could use uv tool run which isn't the case so I dropped this message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

};

let mut tools = installed_tools.tools()?.into_iter().collect::<Vec<_>>();
tools.sort_by_key(|(name, _)| name.clone());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using sort_by_key I use sorted_by to avoid the extra clone.

Comment on lines +297 to +305
// Skip invalid tools
.filter_map(|(name, tool)| {
tool.ok().and_then(|_| {
installed_tools
.version(&name, cache)
.ok()
.map(|version| (name, version))
})
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do all the filtering here, so we don't need to use a buf: String later.

Comment on lines -314 to 323

let mut buf = String::new();
for (name, tool) in tools {
// Skip invalid tools.
let Ok(tool) = tool else {
continue;
};

// Output tool name and version.
let Ok(version) = installed_tools.version(&name, cache) else {
continue;
};
writeln!(buf, "{}", format!("{name} v{version}").bold())?;

// Output tool entrypoints.
for entrypoint in tool.entrypoints() {
writeln!(buf, "- {}", entrypoint.name)?;
}
// Display the tools
writeln!(printer.stdout(), "The following tools are installed:\n")?;
for (name, version) in tools {
writeln!(
printer.stdout(),
"- {} v{version}",
format!("{name}").bold()
)?;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped the entrypoints, mostly to simplify the output and avoid confusing around --from usage which is a bit more advanced and hard to spell here.

Comment on lines +781 to +783
The following tools are installed:

black v24.2.0
- black
- blackd
- black v24.2.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth on a newline here. I think it looks better if we have an extra newline separating the list? Relevant for #7687

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra line looks way cleaner to me. If you're okay with me putting it here, I will change the other PR.

Copy link
Member Author

@zanieb zanieb Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeah sorry I think I (wrongly) suggested you remove it over there

@zanieb zanieb marked this pull request as ready for review September 27, 2024 15:16
Copy link
Contributor

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for cleaning things up and making the message much clearer.

These changes made me realize that I still write Rust as if I’m writing Go 😬

match list_available_tools(invocation_source, &cache, printer).await {
// It is a failure because user misses a required tool name.
Ok(()) => return Ok(ExitStatus::Error),
Err(err) => return Err(err),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, way cleaner 🙈

cache: &Cache,
printer: Printer,
) -> anyhow::Result<()> {
let help = format!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines -282 to -283
let no_tools_installed_msg =
"No tools installed. See `uv tool install --help` for more information.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@charliermarsh charliermarsh merged commit 41dbd97 into main Sep 27, 2024
@charliermarsh charliermarsh deleted the zb/tool-help branch September 27, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the command line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants