Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Print all matches instead of erring
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Dec 3, 2019
1 parent 3703074 commit c32a826
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cargo::core::package::PackageSet;
use cargo::core::registry::PackageRegistry;
use cargo::core::resolver::Method;
use cargo::core::shell::Shell;
use cargo::core::{Package, PackageId, Resolve, Workspace};
use cargo::core::{Package, PackageId, PackageIdSpec, Resolve, Workspace};
use cargo::ops;
use cargo::util::{self, important_paths, CargoResult, Cfg, Rustc};
use cargo::{CliResult, Config};
Expand Down Expand Up @@ -209,9 +209,9 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
let ids = packages.package_ids().collect::<Vec<_>>();
let packages = registry.get(&ids)?;

let root = match args.package {
Some(ref pkg) => resolve.query(pkg)?,
None => package.package_id(),
let roots = match args.package {
Some(ref pkg) => query_all(&resolve, pkg)?,
None => vec![package.package_id()],
};

let rustc = config.load_global_rustc(Some(&workspace))?;
Expand Down Expand Up @@ -252,14 +252,20 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
Prefix::Indent
};

if args.duplicates {
let dups = find_duplicates(&graph);
for dup in &dups {
print_tree(dup, &graph, &format, direction, symbols, prefix, args.all)?;
let packages = if args.duplicates {
find_duplicates(&graph)
} else {
roots
};

if packages.len() != 1 {
for package in &packages {
print_tree(package, &graph, &format, direction, symbols, prefix, args.all)?;
println!();
}
} else {
print_tree(&root, &graph, &format, direction, symbols, prefix, args.all)?;
let package = &packages[0];
print_tree(package, &graph, &format, direction, symbols, prefix, args.all)?;
}

Ok(())
Expand Down Expand Up @@ -346,6 +352,17 @@ fn resolve<'a, 'cfg>(
Ok((packages, resolve))
}

fn query_all(resolve: &Resolve, spec: &str) -> CargoResult<Vec<PackageId>> {
let spec = PackageIdSpec::parse(spec)?;
let mut result = vec![];
for package in resolve.iter() {
if spec.matches(package) {
result.push(package);
}
}
Ok(result)
}

struct Node<'a> {
id: PackageId,
metadata: &'a ManifestMetadata,
Expand Down

0 comments on commit c32a826

Please sign in to comment.