@@ -26,6 +26,7 @@ use std::{
26
26
result,
27
27
str:: FromStr ,
28
28
} ;
29
+ use strum:: { IntoEnumIterator , EnumCount } ;
29
30
30
31
type Result < T > = result:: Result < T , Error > ;
31
32
@@ -319,7 +320,7 @@ impl fmt::Display for CommitInfo {
319
320
}
320
321
}
321
322
322
- #[ derive( PartialEq , Eq , EnumString , EnumVariantNames ) ]
323
+ #[ derive( PartialEq , Eq , EnumString , EnumCount , EnumIter , IntoStaticStr ) ]
323
324
#[ strum( serialize_all = "snake_case" ) ]
324
325
enum InfoFields {
325
326
Project ,
@@ -334,6 +335,7 @@ enum InfoFields {
334
335
LinesOfCode ,
335
336
Size ,
336
337
License ,
338
+ UnrecognizedField ,
337
339
}
338
340
339
341
#[ derive( PartialEq , Eq , Hash , Clone , EnumString ) ]
@@ -447,8 +449,21 @@ fn main() -> Result<()> {
447
449
. multiple ( true )
448
450
. takes_value ( true )
449
451
. case_insensitive ( true )
450
- . possible_values ( & InfoFields :: variants ( ) )
451
- . help ( "Disable fields to show" ) )
452
+ . possible_values ( & InfoFields :: iter ( )
453
+ . take ( InfoFields :: count ( ) - 1 )
454
+ . map ( |field| field. into ( ) )
455
+ . collect :: < Vec < & str > > ( )
456
+ . as_slice ( ) )
457
+ . possible_value ( "" )
458
+ . hide_possible_values ( true )
459
+ . default_value ( "" )
460
+ . hide_default_value ( true )
461
+ . help ( & format ! ( "Disable fields to show\n Possible values: {:?}" ,
462
+ & InfoFields :: iter( )
463
+ . take( InfoFields :: count( ) - 1 )
464
+ . map( |field| field. into( ) )
465
+ . collect:: <Vec <& str >>( )
466
+ . as_slice( ) ) ) )
452
467
. arg ( Arg :: with_name ( "colors" )
453
468
. short ( "c" )
454
469
. long ( "colors" )
@@ -504,7 +519,11 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
504
519
let disable_fields: Vec < InfoFields > = if let Some ( values) = matches. values_of ( "disable_field" ) {
505
520
values
506
521
. map ( String :: from)
507
- . map ( |field : String | InfoFields :: from_str ( field. to_lowercase ( ) . as_str ( ) ) . unwrap ( ) )
522
+ . filter_map ( |field : String | {
523
+ let item = InfoFields :: from_str ( field. to_lowercase ( ) . as_str ( ) )
524
+ . unwrap_or ( InfoFields :: UnrecognizedField ) ;
525
+ if item == InfoFields :: UnrecognizedField { None } else { Some ( item) }
526
+ } )
508
527
. collect ( )
509
528
} else {
510
529
Vec :: new ( )
0 commit comments