Skip to content

Commit

Permalink
feat: Add info cargo subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Jun 26, 2024
1 parent 7dcf764 commit f582df0
Show file tree
Hide file tree
Showing 5 changed files with 929 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/bin/cargo/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use cargo::ops::cargo_info::info;
use cargo::util::command_prelude::*;
use cargo_util_schemas::core::PackageIdSpec;

pub fn cli() -> Command {
Command::new("info")
.about("Display information about a package in the registry")
.arg(
Arg::new("package")
.required(true)
.value_name("SPEC")
.help_heading(heading::PACKAGE_SELECTION)
.help("Package to inspect"),
)
.arg_index("Registry index URL to search packages in")
.arg_registry("Registry to search packages in")
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help info</>` for more detailed information.\n"
))
}

pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let package = args
.get_one::<String>("package")
.map(String::as_str)
.unwrap();
let spec = PackageIdSpec::parse(package).map_err(|e| {
anyhow::format_err!(
"invalid package id specification `{}`: {}",
package,
e.to_string()
)
})?;

let reg_or_index = args.registry_or_index(gctx)?;
info(&spec, gctx, reg_or_index)?;
Ok(())
}
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn builtin() -> Vec<Command> {
generate_lockfile::cli(),
git_checkout::cli(),
help::cli(),
info::cli(),
init::cli(),
install::cli(),
locate_project::cli(),
Expand Down Expand Up @@ -59,6 +60,7 @@ pub fn builtin_exec(cmd: &str) -> Option<Exec> {
"generate-lockfile" => generate_lockfile::exec,
"git-checkout" => git_checkout::exec,
"help" => help::exec,
"info" => info::exec,
"init" => init::exec,
"install" => install::exec,
"locate-project" => locate_project::exec,
Expand Down Expand Up @@ -102,6 +104,7 @@ pub mod fix;
pub mod generate_lockfile;
pub mod git_checkout;
pub mod help;
pub mod info;
pub mod init;
pub mod install;
pub mod locate_project;
Expand Down
Loading

0 comments on commit f582df0

Please sign in to comment.