@@ -5,7 +5,7 @@ use cargo::core::package::PackageSet;
5
5
use cargo:: core:: registry:: PackageRegistry ;
6
6
use cargo:: core:: resolver:: Method ;
7
7
use cargo:: core:: shell:: Shell ;
8
- use cargo:: core:: { Package , PackageId , Resolve , Workspace } ;
8
+ use cargo:: core:: { Package , PackageId , PackageIdSpec , Resolve , Workspace } ;
9
9
use cargo:: ops;
10
10
use cargo:: util:: { self , important_paths, CargoResult , Cfg , Rustc } ;
11
11
use cargo:: { CliResult , Config } ;
@@ -209,9 +209,9 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
209
209
let ids = packages. package_ids ( ) . collect :: < Vec < _ > > ( ) ;
210
210
let packages = registry. get ( & ids) ?;
211
211
212
- let root = match args. package {
213
- Some ( ref pkg) => resolve . query ( pkg) ?,
214
- None => package. package_id ( ) ,
212
+ let roots = match args. package {
213
+ Some ( ref pkg) => query_all ( & resolve , pkg) ?,
214
+ None => vec ! [ package. package_id( ) ] ,
215
215
} ;
216
216
217
217
let rustc = config. load_global_rustc ( Some ( & workspace) ) ?;
@@ -252,14 +252,20 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
252
252
Prefix :: Indent
253
253
} ;
254
254
255
- if args. duplicates {
256
- let dups = find_duplicates ( & graph) ;
257
- for dup in & dups {
258
- print_tree ( dup, & graph, & format, direction, symbols, prefix, args. all ) ?;
255
+ let packages = if args. duplicates {
256
+ find_duplicates ( & graph)
257
+ } else {
258
+ roots
259
+ } ;
260
+
261
+ if packages. len ( ) != 1 {
262
+ for package in & packages {
263
+ print_tree ( package, & graph, & format, direction, symbols, prefix, args. all ) ?;
259
264
println ! ( ) ;
260
265
}
261
266
} else {
262
- print_tree ( & root, & graph, & format, direction, symbols, prefix, args. all ) ?;
267
+ let package = & packages[ 0 ] ;
268
+ print_tree ( package, & graph, & format, direction, symbols, prefix, args. all ) ?;
263
269
}
264
270
265
271
Ok ( ( ) )
@@ -346,6 +352,17 @@ fn resolve<'a, 'cfg>(
346
352
Ok ( ( packages, resolve) )
347
353
}
348
354
355
+ fn query_all ( resolve : & Resolve , spec : & str ) -> CargoResult < Vec < PackageId > > {
356
+ let spec = PackageIdSpec :: parse ( spec) ?;
357
+ let mut result = vec ! [ ] ;
358
+ for package in resolve. iter ( ) {
359
+ if spec. matches ( package) {
360
+ result. push ( package) ;
361
+ }
362
+ }
363
+ Ok ( result)
364
+ }
365
+
349
366
struct Node < ' a > {
350
367
id : PackageId ,
351
368
metadata : & ' a ManifestMetadata ,
0 commit comments