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

Commit 6fb5f0b

Browse files
committed
Print all matches instead of erring
1 parent c7e563d commit 6fb5f0b

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

src/tree.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,33 @@ pub fn print(args: &Args, graph: &Graph) -> Result<(), Error> {
5858
Prefix::Indent
5959
};
6060

61-
if args.duplicates {
62-
for (i, package) in find_duplicates(graph).iter().enumerate() {
63-
if i != 0 {
64-
println!();
61+
let packages = if args.duplicates {
62+
find_duplicates(graph)
63+
} else {
64+
match &args.package {
65+
Some(package) => find_packages(package, graph)?,
66+
None => {
67+
let root = graph.root.as_ref().ok_or_else(|| {
68+
anyhow!("this command requires running against an actual package in this workspace")
69+
})?;
70+
vec![root]
6571
}
72+
}
73+
};
6674

67-
let root = &graph.graph[graph.nodes[*package]];
68-
print_tree(graph, root, &format, direction, symbols, prefix, args.all);
75+
for (i, package) in packages.iter().enumerate() {
76+
if i != 0 {
77+
println!();
6978
}
70-
} else {
71-
let root = match &args.package {
72-
Some(package) => find_package(package, graph)?,
73-
None => graph.root.as_ref().ok_or_else(|| {
74-
anyhow!("this command requires running against an actual package in this workspace")
75-
})?,
76-
};
77-
let root = &graph.graph[graph.nodes[root]];
7879

80+
let root = &graph.graph[graph.nodes[*package]];
7981
print_tree(graph, root, &format, direction, symbols, prefix, args.all);
8082
}
8183

8284
Ok(())
8385
}
8486

85-
fn find_package<'a>(package: &str, graph: &'a Graph) -> Result<&'a PackageId, Error> {
87+
fn find_packages<'a>(package: &str, graph: &'a Graph) -> Result<Vec<&'a PackageId>, Error> {
8688
let mut it = package.split(":");
8789
let name = it.next().unwrap();
8890
let version = it
@@ -104,24 +106,13 @@ fn find_package<'a>(package: &str, graph: &'a Graph) -> Result<&'a PackageId, Er
104106
}
105107
}
106108

107-
candidates.push(package);
109+
candidates.push(&package.id);
108110
}
109111

110112
if candidates.len() == 0 {
111113
Err(anyhow!("no crates found for package `{}`", package))
112-
} else if candidates.len() > 1 {
113-
let specs = candidates
114-
.iter()
115-
.map(|p| format!("{}:{}", p.name, p.version))
116-
.collect::<Vec<_>>()
117-
.join(", ");
118-
Err(anyhow!(
119-
"multiple crates found for package `{}`: {}",
120-
package,
121-
specs,
122-
))
123114
} else {
124-
Ok(&candidates[0].id)
115+
Ok(candidates)
125116
}
126117
}
127118

0 commit comments

Comments
 (0)