-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dcf764
commit b9965c6
Showing
5 changed files
with
1,000 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
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 info 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") | ||
.arg( | ||
opt( | ||
"verbose", | ||
"Use verbose output (-vv very verbose/build.rs output)", | ||
) | ||
.short('v') | ||
.action(ArgAction::Count) | ||
.global(true), | ||
) | ||
.arg( | ||
flag("quiet", "Do not print cargo log messages") | ||
.short('q') | ||
.global(true), | ||
) | ||
.arg( | ||
opt("color", "Coloring: auto, always, never") | ||
.value_name("WHEN") | ||
.global(true), | ||
) | ||
.arg( | ||
flag("frozen", "Require Cargo.lock and cache are up to date") | ||
.help_heading(heading::MANIFEST_OPTIONS) | ||
.global(true), | ||
) | ||
.arg( | ||
flag("locked", "Require Cargo.lock is up to date") | ||
.help_heading(heading::MANIFEST_OPTIONS) | ||
.global(true), | ||
) | ||
.arg( | ||
flag("offline", "Run without accessing the network") | ||
.help_heading(heading::MANIFEST_OPTIONS) | ||
.global(true), | ||
) | ||
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) | ||
.arg( | ||
Arg::new("unstable-features") | ||
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") | ||
.short('Z') | ||
.value_name("FLAG") | ||
.action(ArgAction::Append) | ||
.global(true), | ||
) | ||
.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 verbose = args.verbose(); | ||
let quiet = args.flag("quiet"); | ||
let color = args.get_one::<String>("color").cloned(); | ||
let frozen = args.flag("frozen"); | ||
let locked = args.flag("locked"); | ||
let offline = args.flag("offline"); | ||
let unstable_flags: Vec<String> = args | ||
.get_many::<String>("unstable-features") | ||
.unwrap_or_default() | ||
.cloned() | ||
.collect(); | ||
let config_args: Vec<String> = args | ||
.get_many::<String>("config") | ||
.unwrap_or_default() | ||
.cloned() | ||
.collect(); | ||
gctx.configure( | ||
verbose, | ||
quiet, | ||
color.as_deref(), | ||
frozen, | ||
locked, | ||
offline, | ||
&None, | ||
&unstable_flags, | ||
&config_args, | ||
)?; | ||
|
||
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.