Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show description for user-installed binaries when running "cargo --list" #13847

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Oakchris1955
Copy link

What does this PR try to resolve?

I've noticed that when running cargo --list, user-installed subcommands wouldn't have a description. In order to resolve this, cargo will now communicate with the crates.io registry (if those packages were installed from crates.io ofc) and retrieve the package description from there. This also works if the binary name is different than the name of the package (for example, if a package installs multiple binaries)

How should we test and review this PR?

I've noticed that some test use the --list flag, so if they pass, this should be fine

Additional information

crates.io allows someone to go to https://crates.io/api/v1/crates/{crate} and get info about this crate in a JSON format. However, from what I've found, this isn't standardized for other Rust registries, and so, if a subcommand was installed from another registry, it won't print a description. Please verify that this is the case. If not, I can remove the relevant checks for other registries.

IMPORTANT

I haven't fixed the relevant tests yet, so DON'T merge this immediately

Also added a description method for the Registry struct in crates/crates-io/lib.rs and change submodule's "common_for_install_uninstall" visibility to public. All these changes were necessary in order to implement the forementioned feature
@rustbot
Copy link
Collaborator

rustbot commented May 2, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-interacts-with-crates.io Area: interaction with registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2024
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution.

There is an issue tracking this #10662. Per the contributing guide, we'd like to have a design discussion before diving into implementation details.

@@ -393,6 +414,8 @@ impl Registry {
headers.append("Content-Type: application/json")?;
}

headers.append(&format!("User-Agent: cargo-cli"))?;
Copy link
Member

Choose a reason for hiding this comment

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

This is not ideal. Cargo has its own user-agent header when communicating with crates.io. This kind of setting should be in cargo main crate, not crates-io. Also there is curl::easy::Easy::useragent you could use. `

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I did some searching around and found that in cargo::util::network::http exists a function named http_handle that autoconfigures things like the user-agent, etc. based on the gctx (GlobalContext) variable. I assume it is ok to use that?

.cloned();

if let Some(installed_by) = installed_by {
let desc = registry.description(&installed_by).ok().flatten();
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I feel like it's overkill talking over the network for descriptions. Yet, let's back to design discussion first.

Copy link
Author

Choose a reason for hiding this comment

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

Querying the network for such little things is overkill indeed. However, from what I've found,currently no other better way to do this exists.
Perhaps what could be done here is implement some form of cache to store binaries' descriptions so that we don't have to query them each time.

@Oakchris1955
Copy link
Author

I might have found why those tests are failing. For some reason, by making those changes to the code, cargo --list now generates trailing whitespaces on every end of line of subcommands without a description, even though I couldn't narrow down why this happens. Any help would be appreciated

@weihanglo
Copy link
Member

I am not going to discuss any specific implementation further until we have a conclusion on the design. Could we bring it back to #10662, and gather ideas there?

@weihanglo weihanglo added Command-install S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. A-custom-subcommands Area: custom 3rd party subcommand plugins and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. Command-install labels May 3, 2024
@weihanglo weihanglo marked this pull request as draft May 3, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-custom-subcommands Area: custom 3rd party subcommand plugins A-interacts-with-crates.io Area: interaction with registries S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants