Skip to content

Use file hyperlinks when outputting target names when running cargo run --bin and the like. #15401

Closed
@kpbaks

Description

@kpbaks

Problem

In a project with multiple binaries, examples, tests, benches or packages commands like cargo run, cargo run --bin cargo run --example, cargo test --bench will generate an error with the list of available targets and remind the user to pick one of them. This is a good user experience as it helps the user easily discover what targets are available. I think this experience could be improved if the targets where outputted using ANSI hyperlinks, where package targets would be formatted to have a hyperlink to the file path of the crates Cargo.toml and binary targets like --bin and --example would be the file path to the file containing its main function. With this the user can easily click on the target if it's unclear where the target orginates from or how its defined and have the file open in their editor.

Proposed Solution

Change print_available_targets() and print_available_packages() in src/cargo/util/workspace.rs to use Shell to format each target as a hyperlink.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-console-outputArea: Terminal output, colors, progress bar, etc.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions