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

Display builtin aliases with cargo --list #8542

Merged
merged 5 commits into from
Jul 28, 2020
Merged

Conversation

CPerezz
Copy link
Contributor

@CPerezz CPerezz commented Jul 24, 2020

As stated in #8486 it would help to the discovery of the
builtin aliases the facto of printing them with the
cargo --list command.

  • Extracted the builtin aliases currently implemented to a
    separated const.
  • Make all of the functions that interact with these aliases
    point to that function.
  • Refactored the list_commands fn in order to include with the
    builtin and external commands, the builtin aliases that come with
    cargo by default.
  • Added a test that checks that the aliases that currently
    are builtin with cargo are indeed being printed with the rest
    of the commands when cargo --list is called.

The output on my machine looks like this:

$ cargo --list
Installed Commands:
    b                    alias: build
    bench                Execute all benchmarks of a local package
    build                Compile a local package and all of its dependencies
    c                    alias: check
    check                Check a local package and all of its dependencies for errors
    clean                Remove artifacts that cargo has generated in the past
    doc                  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 subcommand has been removed
    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.
    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
    r                    alias: run
    read-manifest        Print a JSON representation of a Cargo.toml manifest.
    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
    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
    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
    clippy
    clippy
    clippy
    clippy
    flamegraph
    fmt
    fmt
    fmt
    fmt
    miri
    miri
    miri
    miri
    outdated
    tree

As discussed with @ehuss the BTreeSet enforces Ord therefore, the aliases get mixed with the commands since they're passed through the same function.

It can be refactored to appear separately, but, the code will be more spread and now it's all in just one file (which I believe is easier to maintain and review).

Closes #8486

CPerezz and others added 4 commits April 27, 2020 12:26
As stated in rust-lang#8486 it would help to the discovery of the
builtin aliases the facto of printing them with the
`cargo --list` command.

- Extracted the builtin aliases currently implemented to a
sepparated `const`.
- Make all of the functions that interact with these aliases
point to that function.
- Refactored the `list_commands` fn in order to include with the
builtin and external commands, the builtin aliases that come with
cargo by defaut.
Added a test that checks that the aliases that currently
are builtin with cargo are indeed being printed with the rest
of the commands when `cargo --list` is called.

Closes rust-lang#8486
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2020
@alexcrichton
Copy link
Member

@bors: r+

Looks great to me, thanks @CPerezz!

@bors
Copy link
Contributor

bors commented Jul 28, 2020

📌 Commit 7b16c7c has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2020
/// corresponding execs represented as &str.
fn builtin_aliases_execs(cmd: &str) -> Option<&str> {
match cmd {
"b" => Some("build"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of defining the set of aliases twice, perhaps just place them all in a single table? Like a 3-element tuple (alias, command, description), and then builtin_aliases_execs could just iterate over the array and find a match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's brilliant!! Will modify it!!

@alexcrichton
Copy link
Member

@bors: r-

er, @ehuss has a good point!

@bors bors added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 28, 2020
As @ehuss correctly suggested, we could just declare
in one `const` structure for every builtin alias the
following: `(alias, aliased_command, description)`.

Therefore, the suggestion has been applied and the
`BUILTIN_ALIASES` const has been refactored.

Also, the `builtin_aliases_execs` now parses the
`BUILTIN_ALIASES` const searching for a
"possible alias command" returning an option with the
previous info structure or `None`.
@CPerezz CPerezz requested a review from ehuss July 28, 2020 18:57
@CPerezz
Copy link
Contributor Author

CPerezz commented Jul 28, 2020

I think this should do it. I'm considering to open a followup issue in respect to that and move all of the "aliased" stuff to a separate file so it's easier to upgrade on the future.

Suggestions are welcomed @alexcrichton @ehuss

@ehuss
Copy link
Contributor

ehuss commented Jul 28, 2020

Thanks! 😄

@bors r+

@bors
Copy link
Contributor

bors commented Jul 28, 2020

📌 Commit 2ae8df6 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Jul 28, 2020
@bors
Copy link
Contributor

bors commented Jul 28, 2020

⌛ Testing commit 2ae8df6 with merge 2d26633...

@bors
Copy link
Contributor

bors commented Jul 28, 2020

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 2d26633 to master...

@bors bors merged commit 2d26633 into rust-lang:master Jul 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2020
Update cargo

14 commits in aa6872140ab0fa10f641ab0b981d5330d419e927..974eb438da8ced6e3becda2bbf63d9b643eacdeb
2020-07-23 13:46:27 +0000 to 2020-07-29 16:15:05 +0000
- Fix O0 build scripts by default without `[profile.release]` (rust-lang/cargo#8560)
- Emphasize git dependency version locking behavior. (rust-lang/cargo#8561)
- Update lock file encodings on changes (rust-lang/cargo#8554)
- Fix sporadic lto test failures. (rust-lang/cargo#8559)
- build-std: Fix libraries paths following upstream (rust-lang/cargo#8558)
- Flag git http errors as maybe spurious (rust-lang/cargo#8553)
- Display builtin aliases with `cargo --list` (rust-lang/cargo#8542)
- Check manifest for requiring nonexistent features (rust-lang/cargo#7950)
- Clarify test name filter usage (rust-lang/cargo#8552)
- Revert Cargo Book changes for default edition (rust-lang/cargo#8551)
- Prepare for not defaulting to master branch for git deps (rust-lang/cargo#8522)
- Include `+` for crates.io feature requirements in the Cargo Book section on features (rust-lang/cargo#8547)
- Update termcolor and fwdansi versions (rust-lang/cargo#8540)
- Cargo book nitpick in Manifest section (rust-lang/cargo#8543)
@ehuss
Copy link
Contributor

ehuss commented Aug 28, 2020

@CPerezz I just noticed, I had intended for this to also include user aliases. Would you be willing to do a follow-up PR to add those, too?

@CPerezz
Copy link
Contributor Author

CPerezz commented Aug 28, 2020

Hi @ehuss sure! Feel free to open an issue and post your ideas there so I can take a look!

Also, could you please check #8640 since I'm also working on it and I'd need some help.

@ehuss
Copy link
Contributor

ehuss commented Aug 28, 2020

Reopened #8486, let me know if you have any questions on it.

@ehuss ehuss added this to the 1.47.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

display aliases in cargo --list
6 participants