Skip to content

Commit e5feb74

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

File tree

5 files changed

+1000
-0
lines changed

5 files changed

+1000
-0
lines changed

src/bin/cargo/commands/info.rs

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
use cargo::util::command_prelude::*;
2+
use cargo_util_schemas::core::PackageIdSpec;
3+
use cargo::ops::cargo_info::info;
4+
5+
pub fn cli() -> Command {
6+
Command::new("info")
7+
.about("Display info 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(
18+
opt(
19+
"verbose",
20+
"Use verbose output (-vv very verbose/build.rs output)",
21+
)
22+
.short('v')
23+
.action(ArgAction::Count)
24+
.global(true),
25+
)
26+
.arg(
27+
flag("quiet", "Do not print cargo log messages")
28+
.short('q')
29+
.global(true),
30+
)
31+
.arg(
32+
opt("color", "Coloring: auto, always, never")
33+
.value_name("WHEN")
34+
.global(true),
35+
)
36+
.arg(
37+
flag("frozen", "Require Cargo.lock and cache are up to date")
38+
.help_heading(heading::MANIFEST_OPTIONS)
39+
.global(true),
40+
)
41+
.arg(
42+
flag("locked", "Require Cargo.lock is up to date")
43+
.help_heading(heading::MANIFEST_OPTIONS)
44+
.global(true),
45+
)
46+
.arg(
47+
flag("offline", "Run without accessing the network")
48+
.help_heading(heading::MANIFEST_OPTIONS)
49+
.global(true),
50+
)
51+
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
52+
.arg(
53+
Arg::new("unstable-features")
54+
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
55+
.short('Z')
56+
.value_name("FLAG")
57+
.action(ArgAction::Append)
58+
.global(true),
59+
)
60+
.after_help(color_print::cstr!(
61+
"Run `<cyan,bold>cargo help info</>` for more detailed information.\n"
62+
))
63+
}
64+
65+
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
66+
let verbose = args.verbose();
67+
let quiet = args.flag("quiet");
68+
let color = args.get_one::<String>("color").cloned();
69+
let frozen = args.flag("frozen");
70+
let locked = args.flag("locked");
71+
let offline = args.flag("offline");
72+
let unstable_flags: Vec<String> = args
73+
.get_many::<String>("unstable-features")
74+
.unwrap_or_default()
75+
.cloned()
76+
.collect();
77+
let config_args: Vec<String> = args
78+
.get_many::<String>("config")
79+
.unwrap_or_default()
80+
.cloned()
81+
.collect();
82+
gctx.configure(
83+
verbose,
84+
quiet,
85+
color.as_deref(),
86+
frozen,
87+
locked,
88+
offline,
89+
&None,
90+
&unstable_flags,
91+
&config_args,
92+
)?;
93+
94+
let package = args
95+
.get_one::<String>("package")
96+
.map(String::as_str)
97+
.unwrap();
98+
let spec = PackageIdSpec::parse(package).map_err(|e| {
99+
anyhow::format_err!(
100+
"invalid package id specification `{}`: {}",
101+
package,
102+
e.to_string()
103+
)
104+
})?;
105+
106+
let reg_or_index = args.registry_or_index(gctx)?;
107+
info(&spec, gctx, reg_or_index)?;
108+
Ok(())
109+
}

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)