Commit f3fee6d
committed
Auto merge of #14141 - hi-rustin:rustin-patch-info, r=epage
feat: Add `info` cargo subcommand
<!-- homu-ignore:start -->
close #14081
close #948
fcp #14141 (comment)
This PR added a new `info` cargo subcommand.
# Background
This adds a new subcommand to Cargo, `cargo info`. This subcommand would allow users to get information about a crate from the command line, without having to go to the web.
The main motivation for this is to make it easier to get information about a crate from the command line. Currently, the way to get information about a crate is to go to the web and look it up on [crates.io] or find the crate's source code and look at the `Cargo.toml` file. This is not very convenient, especially not all information is displayed on the [crates.io] page.
This command also has been requested by the community for a long time. You can find more discussion about this in [cargo#948].
Another motivation is to make the workflow of finding and evaluating crates more efficient. In the current workflow, users can search for crates using `cargo search`, but then they have to go to the web to get more information about the crate. This is not very efficient, especially if the user is just trying to get a quick overview of the crate. This would allow users to quickly get information about a crate without having to leave the terminal.
[crates.io]: https://crates.io
[cargo#948]: #948
Example usage:
```console
./target/debug/cargo info clap --verbose
Credential cargo:token get crates-io
clap #argument #cli #arg #parser #parse
A simple to use, efficient, and full-featured Command Line Argument Parser
version: 4.5.8 (latest 4.5.9)
license: MIT OR Apache-2.0
rust-version: 1.74
documentation: https://docs.rs/clap/4.5.8
repository: https://github.com/clap-rs/clap
crates.io: https://crates.io/crates/clap/4.5.8
features:
+default = [std, color, help, usage, error-context, suggestions]
color = [clap_builder/color]
error-context = [clap_builder/error-context]
help = [clap_builder/help]
std = [clap_builder/std]
suggestions = [clap_builder/suggestions]
usage = [clap_builder/usage]
cargo = [clap_builder/cargo]
debug = [clap_builder/debug, clap_derive?/debug]
deprecated = [clap_builder/deprecated, clap_derive?/deprecated]
derive = [dep:clap_derive]
env = [clap_builder/env]
string = [clap_builder/string]
unicode = [clap_builder/unicode]
unstable-doc = [clap_builder/unstable-doc, derive]
unstable-styles = [clap_builder/unstable-styles]
unstable-v5 = [clap_builder/unstable-v5, clap_derive?/unstable-v5, deprecated]
wrap_help = [clap_builder/wrap_help]
dependencies:
+clap_builder@=4.5.8
clap_derive@=4.5.8
owners:
kbknapp (Kevin K.)
github:rust-cli:maintainers (Maintainers)
github:clap-rs:admins (Admins)
note: to see how you depend on clap, run `cargo tree --invert --package clap@4.5.8`
```
<img width="1425" alt="image" src="https://github.com/user-attachments/assets/e0813c45-624f-417c-a61d-eda03f9ab5ed">
*note:* this is showing the `--verbose` output to show every thing the user can possibly see. Normal operation does not include
- dependencies
## Detailed design
| Content | Explanation | Why |
|----------------------------------------------------------------------------|-------------------------------------|-----------------------------------------------------------------------------------|
| clap | Name | The basic information. |
| #argument #cli #arg #parser #parse | Keywords (clickable) | It's more like a category, which you can use to search for relevant alternatives. |
| A simple to use, efficient, and full-featured Command Line Argument Parser | Description | The basic information. |
| version: 4.5.8 (latest 4.5.9) | Version | The basic information. |
| license: MIT OR Apache-2.0 | License | When choosing a crate, it is crucial to consider the license. |
| rust-version: 1.74 | MSRV | When choosing a crate, it is crucial to make sure it can work with your MSRV. |
| documentation: <https://docs.rs/clap/4.5.8> | Documentation Link | Use these links can find more docs and information. |
| repository: <https://github.com/clap-rs/clap> | Repo Link | Use these links can find more docs and information. |
| crates.io: https://crates.io/crates/clap/4.5.8 | crates.io Link | Use these links can find more docs and information. |
| features: | Default Features And Other Features | It helps for enabling features. |
| dependencies: | All dependencies | It indicates what it depends on. |
| owners: | Owners | It indicates who maintains the crate. |
| note: to see how you depend on clap, run `cargo tree --invert --package clap@4.5.8` | A note for cargo tree command | It will prompt the user that the package is depended on under the workspace, and the dependencies can be viewed using the cargo tree command. |
## Rendering features
- For features enabled by users, a + prefix and colored output are now used for better visibility.
- For features enabled automatically, colored output is used to distinguish them.
- For disabled features, non-colored output is used to clearly indicate their status.
## Rendering deps
Only show dependencies in verbose mode.
- For dependencies required by the package, a + prefix and colored output are now used for better visibility.
- For dependencies that are optional and activated, colored output is used to distinguish them.
- For dependencies that are optional and not activated, non-colored output is used to clearly indicate their status.
# Some important notes
## Downloading the crate from any Cargo compatible registry
The `cargo info` command will download the crate from any Cargo compatible registry. It will then extract the information from the `Cargo.toml` file and display it in the terminal.
If the crate is already in the local cache, it will not download the crate again. It will get the information from the local cache.
## Pick the correct version from the workspace
When executed in a workspace directory, the cargo info command chooses the version that the workspace is currently using.
If there's a lock file available, the version from this file will be used. In the absence of a lock file, the command attempts to select a version that is compatible with the Minimum Supported Rust Version (MSRV). And the lock file will be generated automatically.
The following hierarchy is used to determine the MSRV:
- First, the MSRV of the parent directory package is checked, if it exists.
- If the parent directory package does not specify an MSRV, the minimal MSRV of the workspace is checked.
- If neither the workspace nor the parent directory package specify an MSRV, the version of the current Rust compiler (rustc --version) is used.
# Prior art
## NPM
[npm] has a similar command called `npm info`.
For example:
```console
$ npm info lodash
lodash@4.17.21 | MIT | deps: none | versions: 114
Lodash modular utilities.
https://lodash.com/
keywords: modules, stdlib, util
dist
.tarball: https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz
.shasum: 679591c564c3bffaae8454cf0b3df370c3d6911c
.integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
.unpackedSize: 1.4 MB
maintainers:
- mathias <mathias@qiwi.be>
- jdalton <john.david.dalton@gmail.com>
- bnjmnt4n <benjamin@dev.ofcr.se>
dist-tags:
latest: 4.17.21
published over a year ago by bnjmnt4n <benjamin@dev.ofcr.se>
```
[npm]: https://www.npmjs.com/
## Poetry
[Poetry] has a similar command called `poetry show`.
For example:
```console
$ poetry show pendulum
name : pendulum
version : 1.4.2
description : Python datetimes made easy
dependencies
- python-dateutil >=2.6.1
- tzlocal >=1.4
- pytzdata >=2017.2.2
required by
- calendar >=1.4.0
```
[Poetry]: https://python-poetry.org/
# insta-stable
As `@weihanglo` mentioned in #14141 (comment), commands that shadow third-party commands tend to be insta-stabilized to avoid an intermediate period where users can't access the third-party command (built-ins get priority) nor the built-in command (requires nightly)
For the cargo-info command, there are two commands that this would shadow
- [cargo-information](https://github.com/hi-rustin/cargo-information): hasn't been around too long and only has 4k downloads
- [cargo-info](https://gitlab.com/imp/cargo-info) : been around longer and has 63k downloads
We might be able to get away with having this unstable but starting from the assumption of insta-stabilization.File tree
206 files changed
+5563
-1
lines changed- src
- bin/cargo/commands
- cargo/ops
- registry
- info
- doc
- man
- generated_txt
- src
- commands
- etc
- man
- tests/testsuite
- cargo_info
- basic
- features_activated_over_limit_verbose
- features_activated_over_limit
- features_deactivated_over_limit
- features
- git_dependency
- help
- not_found
- out
- src
- path_dependency
- in
- crates/crate1
- src
- src
- out
- crates/crate1
- src
- src
- pick_msrv_compatible_package_within_ws_and_use_msrv_from_ws
- in
- crate1
- src
- crate2
- src
- out
- crate1
- src
- crate2
- src
- pick_msrv_compatible_package_within_ws
- in
- crate1
- src
- crate2
- src
- out
- crate1
- src
- crate2
- src
- pick_msrv_compatible_package
- specify_empty_version_with_url
- specify_version_outside_ws
- specify_version_with_url_but_registry_is_not_matched
- specify_version_within_ws_and_conflict_with_lockfile
- out
- src
- specify_version_within_ws_and_match_with_lockfile
- out
- src
- transitive_dependency_within_ws
- in
- crates
- direct1
- src
- direct2
- src
- transitive123
- src
- transitive1
- src
- transitive2
- src
- src
- out
- crates
- direct1
- src
- direct2
- src
- transitive123
- src
- transitive1
- src
- transitive2
- src
- src
- verbose
- with_frozen_outside_ws
- with_frozen_within_ws
- out
- src
- with_locked_outside_ws
- with_locked_within_ws_and_pick_the_package
- in
- src
- out
- src
- with_locked_within_ws
- out
- src
- with_offline
- with_quiet
- within_workspace.in
- src
- within_ws_and_pick_ws_package
- in
- src
- out
- src
- within_ws_with_alternative_registry
- out
- src
- within_ws_without_lockfile
- in
- src
- out
- src
- within_ws
- out
- src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
206 files changed
+5563
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
0 commit comments