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

Improve cargo --list output (split output into sections) #12196

Closed
wants to merge 1 commit into from

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented May 28, 2023

(Related to #12114 , but the scope of that issue is bigger and this PR doesn't close it.)

What does this PR try to resolve?

cargo --list's output is really bad. It mixes aliases, builtin commands and external commands.
It would look something like this:

$ cargo --list
Installed Commands:
    add                  Add dependencies to a Cargo.toml manifest file
    b                    alias: build
    bench                Execute all benchmarks of a local package
    build                Compile a local package and all of its dependencies
    build-man            alias: run --package xtask-build-man --
    bump
    c                    alias: check
    check                Check a local package and all of its dependencies for errors
    checktests
    clean                Remove artifacts that cargo has generated in the past
    clippy               Checks a package to catch common mistakes and improve your Rust code.
    config               Inspect configuration values
    d                    alias: doc
    doc                  Build a package's documentation
    examples
    expand
    fetch                Fetch dependencies of a package from the network
    fix                  Automatically fix lint warnings reported by rustc
    flowistry
    fmt                  Formats all bin and lib files of the current crate using rustfmt.
    generate
    generate-lockfile    Generate the lockfile for a package
    git-checkout         This command has been removed
    help                 Displays help for a cargo subcommand
    init                 Create a new cargo package in an existing directory
    install              Install a Rust binary. Default location is $HOME/.cargo/bin
    is-tested
    locate-project       Print a JSON representation of a Cargo.toml file's location
    login                Save an api token from the registry locally. If token is not specified, it will be read from stdin.
    logout               Remove an API token from the registry locally
    metadata             Output the resolved dependencies of a package, the concrete used versions including overrides, in machine-readable format
    miri
    new                  Create a new cargo package at <path>
    owner                Manage the owners of a crate on the registry
    package              Assemble the local package into a distributable tarball
    pkgid                Print a fully qualified package specification
    publish              Upload a package to the registry
    r                    alias: run
    rdme
    read-manifest        Print a JSON representation of a Cargo.toml manifest.
    remove               Remove dependencies from a Cargo.toml manifest file
    report               Generate and display various kinds of reports
    rm                   alias: remove
    run                  Run a binary or example of the local package
    rustc                Compile a package, and pass extra options to the compiler
    rustdoc              Build a package's documentation, using specified custom flags.
    search               Search packages in crates.io
    set-version
    stale-label          alias: run --package xtask-stale-label --
    t                    alias: test
    test                 Execute all unit and integration tests and build examples of a local package
    tree                 Display a tree visualization of a dependency graph
    udeps
    uninstall            Remove a Rust binary
    unpublished          alias: run --package xtask-unpublished --
    update               Update dependencies as recorded in the local lock file
    upgrade
    vendor               Vendor all dependencies for a project locally
    verify-project       Check correctness of crate manifest
    version              Show version information
    watch
    yank                 Remove a pushed crate from the index

Finding a command is very hard in this list. That's why this PR aims to fix this list.
It groups builtin commands, external and aliases in three different sections. It also groups builtin commands with its builtin aliases.

    build, b             Compile a local package and all of its dependencies

The final output looks like this

$ cargo run -- --list
Installed Commands:
====================
  Builtin commands:
    add                  Add dependencies to a Cargo.toml manifest file
    bench                Execute all benchmarks of a local package
    build, b             Compile a local package and all of its dependencies
    check, c             Check a local package and all of its dependencies for errors
    clean                Remove artifacts that cargo has generated in the past
    config               Inspect configuration values
    doc, d               Build a package's documentation
    fetch                Fetch dependencies of a package from the network
    fix                  Automatically fix lint warnings reported by rustc
    generate-lockfile    Generate the lockfile for a package
    git-checkout         This command has been removed
    help                 Displays help for a cargo subcommand
    init                 Create a new cargo package in an existing directory
    install              Install a Rust binary. Default location is $HOME/.cargo/bin
    locate-project       Print a JSON representation of a Cargo.toml file's location
    login                Save an api token from the registry locally. If token is not specified, it will be read from stdin.
    logout               Remove an API token from the registry locally
    metadata             Output the resolved dependencies of a package, the concrete used versions including overrides, in machine-readable format
    new                  Create a new cargo package at <path>
    owner                Manage the owners of a crate on the registry
    package              Assemble the local package into a distributable tarball
    pkgid                Print a fully qualified package specification
    publish              Upload a package to the registry
    read-manifest        Print a JSON representation of a Cargo.toml manifest.
    remove, rm           Remove dependencies from a Cargo.toml manifest file
    report               Generate and display various kinds of reports
    run, r               Run a binary or example of the local package
    rustc                Compile a package, and pass extra options to the compiler
    rustdoc              Build a package's documentation, using specified custom flags.
    search               Search packages in crates.io
    test, t              Execute all unit and integration tests and build examples of a local package
    tree                 Display a tree visualization of a dependency graph
    uninstall            Remove a Rust binary
    update               Update dependencies as recorded in the local lock file
    vendor               Vendor all dependencies for a project locally
    verify-project       Check correctness of crate manifest
    version              Show version information
    yank                 Remove a pushed crate from the index
====================
  External commands:
    bump
    checktests
    clippy               Checks a package to catch common mistakes and improve your Rust code.
    examples
    expand
    flowistry
    fmt                  Formats all bin and lib files of the current crate using rustfmt.
    generate
    is-tested
    miri
    mommy
    rdme
    set-version
    udeps
    upgrade
    watch
====================
  Aliases:
    b                    build
    build-man            run --package xtask-build-man --
    c                    check
    d                    doc
    r                    run
    rm                   remove
    stale-label          run --package xtask-stale-label --
    t                    test
    unpublished          run --package xtask-unpublished --

How should we test and review this PR?

Execute cargo run -- --list (in the Cargo repository) and check that the output is better than before.

@rustbot
Copy link
Collaborator

rustbot commented May 28, 2023

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) soon.

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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 28, 2023
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 being interested in fixing that. However the issue is not yet accepted because the concerns around shell upgrade path are not clear. See #12114 (comment) and #12093 (comment)

That's why cargo help --commands was proposed. #12093 contains more contexts. Sorry that was my mistake closing that and suggested opening a new issue.

@blyxyas
Copy link
Member Author

blyxyas commented May 28, 2023

I'll close it and elaborate on #12114

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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants