summaryrefslogtreecommitdiffstats
path: root/src/bin/cargo/commands/pkgid.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/cargo/commands/pkgid.rs')
-rw-r--r--src/bin/cargo/commands/pkgid.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bin/cargo/commands/pkgid.rs b/src/bin/cargo/commands/pkgid.rs
new file mode 100644
index 0000000..664db75
--- /dev/null
+++ b/src/bin/cargo/commands/pkgid.rs
@@ -0,0 +1,28 @@
+use crate::command_prelude::*;
+
+use cargo::ops;
+use cargo::util::print_available_packages;
+
+pub fn cli() -> Command {
+ subcommand("pkgid")
+ .about("Print a fully qualified package specification")
+ .arg_quiet()
+ .arg(Arg::new("spec").action(ArgAction::Set))
+ .arg_package("Argument to get the package ID specifier for")
+ .arg_manifest_path()
+ .after_help("Run `cargo help pkgid` for more detailed information.\n")
+}
+
+pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
+ let ws = args.workspace(config)?;
+ if args.is_present_with_zero_values("package") {
+ print_available_packages(&ws)?
+ }
+ let spec = args
+ .get_one::<String>("spec")
+ .or_else(|| args.get_one::<String>("package"))
+ .map(String::as_str);
+ let spec = ops::pkgid(&ws, spec)?;
+ cargo::drop_println!(config, "{}", spec);
+ Ok(())
+}