Skip to content

Commit 0d2a243

Browse files
committed
Add a pkgid id command and update docopt docs
1 parent 49335f2 commit 0d2a243

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
lines changed

src/bin/cargo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ macro_rules! each_subcommand( ($macro:ident) => ({
6262
$macro!(login)
6363
$macro!(new)
6464
$macro!(package)
65+
$macro!(pkgid)
6566
$macro!(read_manifest)
6667
$macro!(run)
6768
$macro!(test)

src/bin/pkgid.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use docopt;
2+
3+
use cargo::ops;
4+
use cargo::core::MultiShell;
5+
use cargo::util::{CliResult, CliError};
6+
use cargo::util::important_paths::{find_root_manifest_for_cwd};
7+
8+
docopt!(Options, "
9+
Print a fully qualified package specification
10+
11+
Usage:
12+
cargo pkgid [options] [<spec>]
13+
14+
Options:
15+
-h, --help Print this message
16+
--manifest-path PATH Path to the manifest to the package to clean
17+
-v, --verbose Use verbose output
18+
19+
Given a <pkgid> argument, print out the fully qualified package id specifier.
20+
This command will generate an error if <pkgid> is ambiguous as to which package
21+
it refers to in the dependency graph. If no <pkgid> is given, then the pkgid for
22+
the local package is printed.
23+
24+
This command requires that a lockfile is available and dependencies have been
25+
fetched.
26+
27+
Example Package IDs
28+
29+
pkgid | name | version | url
30+
|-----------------------------|--------|-----------|---------------------|
31+
foo | foo | * | *
32+
foo:1.2.3 | foo | 1.2.3 | *
33+
crates.io/foo | foo | * | *://crates.io/foo
34+
crates.io/foo#1.2.3 | foo | 1.2.3 | *://crates.io/foo
35+
crates.io/bar#foo:1.2.3 | foo | 1.2.3 | *://crates.io/bar
36+
http://crates.io/foo#1.2.3 | foo | 1.2.3 | http://crates.io/foo
37+
38+
", flag_manifest_path: Option<String>, arg_spec: Option<String>)
39+
40+
pub fn execute(options: Options,
41+
shell: &mut MultiShell) -> CliResult<Option<()>> {
42+
shell.set_verbose(options.flag_verbose);
43+
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone()));
44+
45+
let spec = options.arg_spec.as_ref().map(|s| s.as_slice());
46+
let spec = try!(ops::pkgid(&root, spec, shell).map_err(|err| {
47+
CliError::from_boxed(err, 101)
48+
}));
49+
println!("{}", spec);
50+
Ok(None)
51+
}
52+

src/bin/update.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ docopt!(Options, "
1010
Update dependencies as recorded in the local lock file.
1111
1212
Usage:
13-
cargo update [options] [<name>]
13+
cargo update [options] [<spec>]
1414
1515
Options:
1616
-h, --help Print this message
@@ -21,22 +21,24 @@ Options:
2121
This command requires that a `Cargo.lock` already exists as generated by
2222
`cargo build` or related commands.
2323
24-
If <name> is specified, then a conservative update of the lockfile will be
25-
performed. This means that only the dependency <name> will be updated. Its
26-
transitive dependencies will be updated only if <name> cannot be updated without
27-
updating dependencies. All other dependencies will remain locked at their
28-
currently recorded versions.
24+
If <spec> is given, then a conservative update of the lockfile will be
25+
performed. This means that only the dependency specified by <spec> will be
26+
updated. Its transitive dependencies will be updated only if <spec> cannot be
27+
updated without updating dependencies. All other dependencies will remain
28+
locked at their currently recorded versions.
2929
30-
If <name> is not specified, then all dependencies will be re-resolved and
30+
If <spec> is not given, then all dependencies will be re-resolved and
3131
updated.
32-
", flag_manifest_path: Option<String>, arg_name: Option<String>)
32+
33+
For more information about package ids, see `cargo help pkgid`.
34+
", flag_manifest_path: Option<String>, arg_spec: Option<String>)
3335

3436
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
3537
debug!("executing; cmd=cargo-update; args={}", os::args());
3638
shell.set_verbose(options.flag_verbose);
3739
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
3840

39-
ops::update_lockfile(&root, shell, options.arg_name, options.flag_aggressive)
41+
ops::update_lockfile(&root, shell, options.arg_spec, options.flag_aggressive)
4042
.map(|_| None).map_err(|err| CliError::from_boxed(err, 101))
4143
}
4244

src/cargo/ops/cargo_generate_lockfile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![warn(warnings)]
21
use std::collections::HashSet;
32
use std::io::File;
43

src/cargo/ops/cargo_pkgid.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use ops;
2+
use core::{MultiShell, Source, PackageIdSpec};
3+
use sources::{PathSource};
4+
use util::{CargoResult, human};
5+
6+
pub fn pkgid(manifest_path: &Path,
7+
spec: Option<&str>,
8+
_shell: &mut MultiShell) -> CargoResult<PackageIdSpec> {
9+
let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
10+
try!(source.update());
11+
let package = try!(source.get_root_package());
12+
13+
let lockfile = package.get_root().join("Cargo.lock");
14+
let source_id = package.get_package_id().get_source_id();
15+
let resolve = match try!(ops::load_lockfile(&lockfile, source_id)) {
16+
Some(resolve) => resolve,
17+
None => return Err(human("A Cargo.lock must exist for this command"))
18+
};
19+
20+
let pkgid = match spec {
21+
Some(spec) => try!(resolve.query(spec)),
22+
None => package.get_package_id(),
23+
};
24+
Ok(PackageIdSpec::from_package_id(pkgid))
25+
}

src/cargo/ops/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use self::cargo_package::package;
1212
pub use self::cargo_upload::{upload, upload_configuration, UploadConfig};
1313
pub use self::cargo_upload::{upload_login, http_proxy, http_handle};
1414
pub use self::cargo_fetch::{fetch, resolve_and_fetch};
15+
pub use self::cargo_pkgid::pkgid;
1516

1617
mod cargo_clean;
1718
mod cargo_compile;
@@ -25,3 +26,4 @@ mod cargo_test;
2526
mod cargo_package;
2627
mod cargo_upload;
2728
mod cargo_fetch;
29+
mod cargo_pkgid;

0 commit comments

Comments
 (0)