Skip to content

Commit 476969f

Browse files
committed
feat: Add info cargo subcommand
1 parent 7dcf764 commit 476969f

File tree

5 files changed

+930
-0
lines changed

5 files changed

+930
-0
lines changed

src/bin/cargo/commands/info.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use cargo::ops::cargo_info::info;
2+
use cargo::util::command_prelude::*;
3+
use cargo_util_schemas::core::PackageIdSpec;
4+
5+
pub fn cli() -> Command {
6+
Command::new("info")
7+
.about("Display information about a package in the registry")
8+
.arg(
9+
Arg::new("package")
10+
.required(true)
11+
.value_name("SPEC")
12+
.help_heading(heading::PACKAGE_SELECTION)
13+
.help("Package to inspect"),
14+
)
15+
.arg_index("Registry index URL to search packages in")
16+
.arg_registry("Registry to search packages in")
17+
.arg_silent_suggestion()
18+
.after_help(color_print::cstr!(
19+
"Run `<cyan,bold>cargo help info</>` for more detailed information.\n"
20+
))
21+
}
22+
23+
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
24+
let package = args
25+
.get_one::<String>("package")
26+
.map(String::as_str)
27+
.unwrap();
28+
let spec = PackageIdSpec::parse(package).map_err(|e| {
29+
anyhow::format_err!(
30+
"invalid package id specification `{}`: {}",
31+
package,
32+
e.to_string()
33+
)
34+
})?;
35+
36+
let reg_or_index = args.registry_or_index(gctx)?;
37+
info(&spec, gctx, reg_or_index)?;
38+
Ok(())
39+
}

src/bin/cargo/commands/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn builtin() -> Vec<Command> {
1414
generate_lockfile::cli(),
1515
git_checkout::cli(),
1616
help::cli(),
17+
info::cli(),
1718
init::cli(),
1819
install::cli(),
1920
locate_project::cli(),
@@ -59,6 +60,7 @@ pub fn builtin_exec(cmd: &str) -> Option<Exec> {
5960
"generate-lockfile" => generate_lockfile::exec,
6061
"git-checkout" => git_checkout::exec,
6162
"help" => help::exec,
63+
"info" => info::exec,
6264
"init" => init::exec,
6365
"install" => install::exec,
6466
"locate-project" => locate_project::exec,
@@ -102,6 +104,7 @@ pub mod fix;
102104
pub mod generate_lockfile;
103105
pub mod git_checkout;
104106
pub mod help;
107+
pub mod info;
105108
pub mod init;
106109
pub mod install;
107110
pub mod locate_project;

0 commit comments

Comments
 (0)