Skip to content

Commit f582df0

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

File tree

5 files changed

+929
-0
lines changed

5 files changed

+929
-0
lines changed

src/bin/cargo/commands/info.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
.after_help(color_print::cstr!(
18+
"Run `<cyan,bold>cargo help info</>` for more detailed information.\n"
19+
))
20+
}
21+
22+
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
23+
let package = args
24+
.get_one::<String>("package")
25+
.map(String::as_str)
26+
.unwrap();
27+
let spec = PackageIdSpec::parse(package).map_err(|e| {
28+
anyhow::format_err!(
29+
"invalid package id specification `{}`: {}",
30+
package,
31+
e.to_string()
32+
)
33+
})?;
34+
35+
let reg_or_index = args.registry_or_index(gctx)?;
36+
info(&spec, gctx, reg_or_index)?;
37+
Ok(())
38+
}

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)