@@ -27,6 +27,8 @@ pub struct TreeOptions {
27
27
/// The dependency kinds to display.
28
28
pub edge_kinds : HashSet < EdgeKind > ,
29
29
pub invert : Vec < String > ,
30
+ /// The packages to prune from the display of the dependency tree.
31
+ pub pkgs_to_prune : Vec < String > ,
30
32
/// The style of prefix for each line.
31
33
pub prefix : Prefix ,
32
34
/// If `true`, duplicates will be repeated.
@@ -199,7 +201,19 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
199
201
graph. invert ( ) ;
200
202
}
201
203
202
- print ( ws. config ( ) , opts, root_indexes, & graph) ?;
204
+ // Packages to prune.
205
+ let pkgs_to_prune = opts
206
+ . pkgs_to_prune
207
+ . iter ( )
208
+ . map ( |p| PackageIdSpec :: parse ( p) )
209
+ . map ( |r| {
210
+ // Provide a error message if pkgid is not within the resolved
211
+ // dependencies graph.
212
+ r. and_then ( |spec| spec. query ( ws_resolve. targeted_resolve . iter ( ) ) . and ( Ok ( spec) ) )
213
+ } )
214
+ . collect :: < CargoResult < Vec < PackageIdSpec > > > ( ) ?;
215
+
216
+ print ( ws. config ( ) , opts, root_indexes, & pkgs_to_prune, & graph) ?;
203
217
Ok ( ( ) )
204
218
}
205
219
@@ -208,6 +222,7 @@ fn print(
208
222
config : & Config ,
209
223
opts : & TreeOptions ,
210
224
roots : Vec < usize > ,
225
+ pkgs_to_prune : & [ PackageIdSpec ] ,
211
226
graph : & Graph < ' _ > ,
212
227
) -> CargoResult < ( ) > {
213
228
let format = Pattern :: new ( & opts. format )
@@ -240,6 +255,7 @@ fn print(
240
255
root_index,
241
256
& format,
242
257
symbols,
258
+ pkgs_to_prune,
243
259
opts. prefix ,
244
260
opts. no_dedupe ,
245
261
opts. max_display_depth ,
@@ -260,6 +276,7 @@ fn print_node<'a>(
260
276
node_index : usize ,
261
277
format : & Pattern ,
262
278
symbols : & Symbols ,
279
+ pkgs_to_prune : & [ PackageIdSpec ] ,
263
280
prefix : Prefix ,
264
281
no_dedupe : bool ,
265
282
max_display_depth : u32 ,
@@ -319,6 +336,7 @@ fn print_node<'a>(
319
336
node_index,
320
337
format,
321
338
symbols,
339
+ pkgs_to_prune,
322
340
prefix,
323
341
no_dedupe,
324
342
max_display_depth,
@@ -339,6 +357,7 @@ fn print_dependencies<'a>(
339
357
node_index : usize ,
340
358
format : & Pattern ,
341
359
symbols : & Symbols ,
360
+ pkgs_to_prune : & [ PackageIdSpec ] ,
342
361
prefix : Prefix ,
343
362
no_dedupe : bool ,
344
363
max_display_depth : u32 ,
@@ -391,6 +410,19 @@ fn print_dependencies<'a>(
391
410
true
392
411
}
393
412
} )
413
+ . filter ( |dep| {
414
+ // Filter out packages to prune.
415
+ if !pkgs_to_prune. is_empty ( ) {
416
+ match graph. node ( * * dep) {
417
+ Node :: Package { package_id, .. } => {
418
+ !pkgs_to_prune. iter ( ) . any ( |spec| spec. matches ( * package_id) )
419
+ }
420
+ _ => true ,
421
+ }
422
+ } else {
423
+ true
424
+ }
425
+ } )
394
426
. peekable ( ) ;
395
427
396
428
while let Some ( dependency) = it. next ( ) {
@@ -401,6 +433,7 @@ fn print_dependencies<'a>(
401
433
* dependency,
402
434
format,
403
435
symbols,
436
+ pkgs_to_prune,
404
437
prefix,
405
438
no_dedupe,
406
439
max_display_depth,
0 commit comments