cargo/src/bin/cargo/commands/pkgid.rs

42 lines
1.5 KiB
Rust
Raw Normal View History

2018-12-06 19:17:36 +00:00
use crate::command_prelude::*;
2018-03-07 15:02:36 +00:00
2018-03-12 21:06:04 +00:00
use cargo::ops;
2018-03-07 15:02:36 +00:00
pub fn cli() -> App {
subcommand("pkgid")
.about("Print a fully qualified package specification")
.arg(Arg::with_name("spec"))
.arg_package("Argument to get the package id specifier for")
2018-03-07 15:02:36 +00:00
.arg_manifest_path()
2018-03-14 15:17:44 +00:00
.after_help(
"\
2018-03-07 15:02:36 +00:00
Given a <spec> argument, print out the fully qualified package id specifier.
This command will generate an error if <spec> is ambiguous as to which package
it refers to in the dependency graph. If no <spec> is given, then the pkgid for
the local package is printed.
This command requires that a lockfile is available and dependencies have been
fetched.
Example Package IDs
pkgid | name | version | url
|-----------------------------|--------|-----------|---------------------|
foo | foo | * | *
foo:1.2.3 | foo | 1.2.3 | *
crates.io/foo | foo | * | *://crates.io/foo
crates.io/foo#1.2.3 | foo | 1.2.3 | *://crates.io/foo
crates.io/bar#foo:1.2.3 | foo | 1.2.3 | *://crates.io/bar
2019-01-30 20:34:37 +00:00
https://crates.io/foo#1.2.3 | foo | 1.2.3 | https://crates.io/foo
2018-03-14 15:17:44 +00:00
",
)
2018-03-07 15:02:36 +00:00
}
2018-03-12 21:06:04 +00:00
2018-12-06 19:21:24 +00:00
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
2018-03-12 21:06:04 +00:00
let ws = args.workspace(config)?;
2018-07-22 16:15:49 +00:00
let spec = args.value_of("spec").or_else(|| args.value_of("package"));
2018-03-12 21:06:04 +00:00
let spec = ops::pkgid(&ws, spec)?;
println!("{}", spec);
Ok(())
}