@@ -43,8 +43,9 @@ pub struct TreeOptions {
4343 pub format : String ,
4444 /// Includes features in the tree as separate nodes.
4545 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 ,
4849 /// Excludes proc-macro dependencies.
4950 pub no_proc_macro : bool ,
5051}
@@ -86,6 +87,30 @@ impl FromStr for Prefix {
8687 }
8788}
8889
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+
89114struct Symbols {
90115 down : & ' static str ,
91116 tee : & ' static str ,
@@ -250,7 +275,7 @@ fn print(
250275 pkgs_to_prune,
251276 opts. prefix ,
252277 opts. no_dedupe ,
253- opts. max_display_depth ,
278+ opts. display_depth ,
254279 & mut visited_deps,
255280 & mut levels_continue,
256281 & mut print_stack,
@@ -270,7 +295,7 @@ fn print_node<'a>(
270295 pkgs_to_prune : & [ PackageIdSpec ] ,
271296 prefix : Prefix ,
272297 no_dedupe : bool ,
273- max_display_depth : u32 ,
298+ display_depth : DisplayDepth ,
274299 visited_deps : & mut HashSet < usize > ,
275300 levels_continue : & mut Vec < bool > ,
276301 print_stack : & mut Vec < usize > ,
@@ -329,7 +354,7 @@ fn print_node<'a>(
329354 pkgs_to_prune,
330355 prefix,
331356 no_dedupe,
332- max_display_depth ,
357+ display_depth ,
333358 visited_deps,
334359 levels_continue,
335360 print_stack,
@@ -349,7 +374,7 @@ fn print_dependencies<'a>(
349374 pkgs_to_prune : & [ PackageIdSpec ] ,
350375 prefix : Prefix ,
351376 no_dedupe : bool ,
352- max_display_depth : u32 ,
377+ display_depth : DisplayDepth ,
353378 visited_deps : & mut HashSet < usize > ,
354379 levels_continue : & mut Vec < bool > ,
355380 print_stack : & mut Vec < usize > ,
@@ -378,6 +403,10 @@ fn print_dependencies<'a>(
378403 }
379404 }
380405
406+ let max_display_depth = match display_depth {
407+ DisplayDepth :: MaxDisplayDepth ( max) => max,
408+ } ;
409+
381410 // Current level exceeds maximum display depth. Skip.
382411 if levels_continue. len ( ) + 1 > max_display_depth as usize {
383412 return ;
@@ -407,7 +436,7 @@ fn print_dependencies<'a>(
407436 pkgs_to_prune,
408437 prefix,
409438 no_dedupe,
410- max_display_depth ,
439+ display_depth ,
411440 visited_deps,
412441 levels_continue,
413442 print_stack,
0 commit comments