@@ -69,25 +69,33 @@ macro_rules! status {
6969pub enum Verbosity {
7070 Quiet ,
7171 Normal ,
72- Verbose ,
72+ Verbose ( u8 ) ,
7373}
7474
7575impl Verbosity {
7676 pub fn verbose ( self ) -> bool {
7777 match self {
78- Self :: Verbose => true ,
78+ Self :: Verbose ( .. ) => true ,
7979 Self :: Normal | Self :: Quiet => false ,
8080 }
8181 }
8282
83- fn create ( color_choice : ColorChoice , verbose : bool , quiet : bool ) -> Option < Self > {
84- match ( verbose, quiet) {
85- ( true , true ) => {
83+ #[ must_use]
84+ pub fn level ( & self ) -> u8 {
85+ match & self {
86+ Verbosity :: Verbose ( v) => * v,
87+ _ => 0 ,
88+ }
89+ }
90+
91+ fn create ( color_choice : ColorChoice , verbose : impl Into < u8 > , quiet : bool ) -> Option < Self > {
92+ match ( verbose. into ( ) , quiet) {
93+ ( 1 .., true ) => {
8694 MessageInfo :: from ( color_choice) . fatal ( "cannot set both --verbose and --quiet" , 101 )
8795 }
88- ( true , false ) => Some ( Verbosity :: Verbose ) ,
89- ( false , true ) => Some ( Verbosity :: Quiet ) ,
90- ( false , false ) => None ,
96+ ( v @ 1 .. , false ) => Some ( Verbosity :: Verbose ( v ) ) ,
97+ ( 0 , true ) => Some ( Verbosity :: Quiet ) ,
98+ ( 0 , false ) => None ,
9199 }
92100 }
93101}
@@ -143,7 +151,7 @@ impl MessageInfo {
143151 }
144152 }
145153
146- pub fn create ( verbose : bool , quiet : bool , color : Option < & str > ) -> Result < MessageInfo > {
154+ pub fn create ( verbose : impl Into < u8 > , quiet : bool , color : Option < & str > ) -> Result < MessageInfo > {
147155 let color_choice = get_color_choice ( color) ?;
148156 let verbosity = get_verbosity ( color_choice, verbose, quiet) ?;
149157
@@ -178,7 +186,7 @@ impl MessageInfo {
178186 }
179187
180188 pub fn as_verbose < T , C : Fn ( & mut MessageInfo ) -> T > ( & mut self , call : C ) -> T {
181- self . as_verbosity ( call, Verbosity :: Verbose )
189+ self . as_verbosity ( call, Verbosity :: Verbose ( 2 ) )
182190 }
183191
184192 fn erase_line < S : Stream + Write > ( & mut self , stream : & mut S ) -> Result < ( ) > {
@@ -397,7 +405,11 @@ fn get_color_choice(color: Option<&str>) -> Result<ColorChoice> {
397405 } )
398406}
399407
400- fn get_verbosity ( color_choice : ColorChoice , verbose : bool , quiet : bool ) -> Result < Verbosity > {
408+ fn get_verbosity (
409+ color_choice : ColorChoice ,
410+ verbose : impl Into < u8 > ,
411+ quiet : bool ,
412+ ) -> Result < Verbosity > {
401413 // cargo always checks the value of these variables.
402414 let env_verbose = cargo_envvar_bool ( "CARGO_TERM_VERBOSE" ) ?;
403415 let env_quiet = cargo_envvar_bool ( "CARGO_TERM_QUIET" ) ?;
0 commit comments