-
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.
Add a pkgid id command and update docopt docs
- Loading branch information
1 parent
49335f2
commit 0d2a243
Showing
6 changed files
with
91 additions
and
10 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
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,52 @@ | ||
use docopt; | ||
|
||
use cargo::ops; | ||
use cargo::core::MultiShell; | ||
use cargo::util::{CliResult, CliError}; | ||
use cargo::util::important_paths::{find_root_manifest_for_cwd}; | ||
|
||
docopt!(Options, " | ||
Print a fully qualified package specification | ||
Usage: | ||
cargo pkgid [options] [<spec>] | ||
Options: | ||
-h, --help Print this message | ||
--manifest-path PATH Path to the manifest to the package to clean | ||
-v, --verbose Use verbose output | ||
Given a <pkgid> argument, print out the fully qualified package id specifier. | ||
This command will generate an error if <pkgid> is ambiguous as to which package | ||
it refers to in the dependency graph. If no <pkgid> 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 | ||
http://crates.io/foo#1.2.3 | foo | 1.2.3 | http://crates.io/foo | ||
", flag_manifest_path: Option<String>, arg_spec: Option<String>) | ||
|
||
pub fn execute(options: Options, | ||
shell: &mut MultiShell) -> CliResult<Option<()>> { | ||
shell.set_verbose(options.flag_verbose); | ||
let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone())); | ||
|
||
let spec = options.arg_spec.as_ref().map(|s| s.as_slice()); | ||
let spec = try!(ops::pkgid(&root, spec, shell).map_err(|err| { | ||
CliError::from_boxed(err, 101) | ||
})); | ||
println!("{}", spec); | ||
Ok(None) | ||
} | ||
|
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#![warn(warnings)] | ||
use std::collections::HashSet; | ||
use std::io::File; | ||
|
||
|
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,25 @@ | ||
use ops; | ||
use core::{MultiShell, Source, PackageIdSpec}; | ||
use sources::{PathSource}; | ||
use util::{CargoResult, human}; | ||
|
||
pub fn pkgid(manifest_path: &Path, | ||
spec: Option<&str>, | ||
_shell: &mut MultiShell) -> CargoResult<PackageIdSpec> { | ||
let mut source = try!(PathSource::for_path(&manifest_path.dir_path())); | ||
try!(source.update()); | ||
let package = try!(source.get_root_package()); | ||
|
||
let lockfile = package.get_root().join("Cargo.lock"); | ||
let source_id = package.get_package_id().get_source_id(); | ||
let resolve = match try!(ops::load_lockfile(&lockfile, source_id)) { | ||
Some(resolve) => resolve, | ||
None => return Err(human("A Cargo.lock must exist for this command")) | ||
}; | ||
|
||
let pkgid = match spec { | ||
Some(spec) => try!(resolve.query(spec)), | ||
None => package.get_package_id(), | ||
}; | ||
Ok(PackageIdSpec::from_package_id(pkgid)) | ||
} |
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