@@ -43,8 +43,9 @@ pub struct TreeOptions {
43
43
pub format : String ,
44
44
/// Includes features in the tree as separate nodes.
45
45
pub graph_features : bool ,
46
- /// Maximum display depth of the dependency tree.
47
- pub max_display_depth : u32 ,
46
+ /// Display depth of the dependency tree.
47
+ /// If non-negative integer, display dependencies with that amount of max depth.
48
+ pub display_depth : DisplayDepth ,
48
49
/// Excludes proc-macro dependencies.
49
50
pub no_proc_macro : bool ,
50
51
}
@@ -86,6 +87,30 @@ impl FromStr for Prefix {
86
87
}
87
88
}
88
89
90
+ #[ derive( Clone , Copy ) ]
91
+ pub enum DisplayDepth {
92
+ MaxDisplayDepth ( u32 ) ,
93
+ }
94
+
95
+ impl FromStr for DisplayDepth {
96
+ type Err = clap:: Error ;
97
+
98
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
99
+ match s {
100
+ s => s. parse ( ) . map ( Self :: MaxDisplayDepth ) . map_err ( |_| {
101
+ clap:: Error :: raw (
102
+ clap:: error:: ErrorKind :: ValueValidation ,
103
+ format ! (
104
+ "supported values for --depth are non-negative integers, \
105
+ but `{}` is unknown",
106
+ s
107
+ ) ,
108
+ )
109
+ } ) ,
110
+ }
111
+ }
112
+ }
113
+
89
114
struct Symbols {
90
115
down : & ' static str ,
91
116
tee : & ' static str ,
@@ -250,7 +275,7 @@ fn print(
250
275
pkgs_to_prune,
251
276
opts. prefix ,
252
277
opts. no_dedupe ,
253
- opts. max_display_depth ,
278
+ opts. display_depth ,
254
279
& mut visited_deps,
255
280
& mut levels_continue,
256
281
& mut print_stack,
@@ -270,7 +295,7 @@ fn print_node<'a>(
270
295
pkgs_to_prune : & [ PackageIdSpec ] ,
271
296
prefix : Prefix ,
272
297
no_dedupe : bool ,
273
- max_display_depth : u32 ,
298
+ display_depth : DisplayDepth ,
274
299
visited_deps : & mut HashSet < usize > ,
275
300
levels_continue : & mut Vec < bool > ,
276
301
print_stack : & mut Vec < usize > ,
@@ -329,7 +354,7 @@ fn print_node<'a>(
329
354
pkgs_to_prune,
330
355
prefix,
331
356
no_dedupe,
332
- max_display_depth ,
357
+ display_depth ,
333
358
visited_deps,
334
359
levels_continue,
335
360
print_stack,
@@ -349,7 +374,7 @@ fn print_dependencies<'a>(
349
374
pkgs_to_prune : & [ PackageIdSpec ] ,
350
375
prefix : Prefix ,
351
376
no_dedupe : bool ,
352
- max_display_depth : u32 ,
377
+ display_depth : DisplayDepth ,
353
378
visited_deps : & mut HashSet < usize > ,
354
379
levels_continue : & mut Vec < bool > ,
355
380
print_stack : & mut Vec < usize > ,
@@ -378,6 +403,10 @@ fn print_dependencies<'a>(
378
403
}
379
404
}
380
405
406
+ let max_display_depth = match display_depth {
407
+ DisplayDepth :: MaxDisplayDepth ( max) => max,
408
+ } ;
409
+
381
410
// Current level exceeds maximum display depth. Skip.
382
411
if levels_continue. len ( ) + 1 > max_display_depth as usize {
383
412
return ;
@@ -407,7 +436,7 @@ fn print_dependencies<'a>(
407
436
pkgs_to_prune,
408
437
prefix,
409
438
no_dedupe,
410
- max_display_depth ,
439
+ display_depth ,
411
440
visited_deps,
412
441
levels_continue,
413
442
print_stack,
0 commit comments