Skip to content

Allow restricting search to crates with binaries for CLI completion purposes #11052

Open
@mqudsi

Description

@mqudsi

Problem

I'm a fish-shell developer, and we have "smarter" cargo completions in addition to those that were previously generated by clap that generate dynamic completions based off the current environment instead of just what's statically baked into the binary via clap (e.g. autocompleting the names of available examples, tests, etc).

I recently added support for autocompleting cargo install ... and cargo add ... by getting crates matching the entered prefix via cargo search but I was wondering if it would be trivial for cargo to support a cargo search --binary-only or cargo search --installable or whatever (even as a hidden/undocumented flag that could change or be removed in the future so it's not a binding commitment) that would restrict the search results to those that contain a binary.

Proposed Solution

I'm not sure if this is technically possible - I would only ask for this feature if such information is readily available from the crate index without introspecting the project itself or doing anything similarly onerous/heavy. Currently we just list all crates and complete both cargo install and cargo add the same way, but with this information we could further restrict completions for cargo install to those that are actually installable.

Notes

If it's not possible it's not a big deal - the only purpose here is to generate more relevant completions since cargo just does a loose string search on the provided keyword and we would be able to generate more applicable results if we could restrict what it returns (e.g. the 10 results cargo search provides are all installable and therefore potential candidates whereas cargo search for certain keywords or partial keywords may return 10 results none of which are installable and therefore none of which are - in the moment - relevant).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-interacts-with-crates.ioArea: interaction with registriesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-searchS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions