@@ -1124,11 +1124,13 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1124
1124
self . validate_blacklist ( & matches) ;
1125
1125
1126
1126
if !self . required . is_empty ( ) {
1127
- println ! ( "reqs: {:?}" , self . required) ;
1128
- println ! ( "bls: {:?}" , self . blacklist) ;
1129
- println ! ( "grps: {:?}" , self . groups) ;
1130
- self . report_error ( "One or more required arguments were not supplied" . to_owned ( ) ,
1131
- true , true ) ;
1127
+ // println!("reqs: {:?}", self.required);
1128
+ // println!("bls: {:?}", self.blacklist);
1129
+ // println!("grps: {:?}", self.groups);
1130
+ if self . validate_required ( & matches) {
1131
+ self . report_error ( "One or more required arguments were not supplied" . to_owned ( ) ,
1132
+ true , true ) ;
1133
+ }
1132
1134
}
1133
1135
1134
1136
matches. usage = Some ( self . create_usage ( ) ) ;
@@ -1504,4 +1506,33 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
1504
1506
}
1505
1507
}
1506
1508
1509
+ fn validate_required ( & self , matches : & ArgMatches < ' ar , ' ar > ) -> bool {
1510
+ for name in self . required . iter ( ) {
1511
+ validate_reqs ! ( self , flags, matches, name) ;
1512
+
1513
+ validate_reqs ! ( self , opts, matches, name) ;
1514
+
1515
+ // because positions use different keys, we dont use the macro
1516
+ match self . positionals_idx . values ( ) . filter ( |ref p| & p. name == name) . next ( ) {
1517
+ Some ( p) =>{
1518
+ if let Some ( ref bl) = p. blacklist {
1519
+ for n in bl. iter ( ) {
1520
+ if matches. args . contains_key ( n) {
1521
+ return false
1522
+ } else if self . groups . contains_key ( n) {
1523
+ let grp = self . groups . get ( n) . unwrap ( ) ;
1524
+ for an in grp. args . iter ( ) {
1525
+ if matches. args . contains_key ( an) {
1526
+ return false
1527
+ }
1528
+ }
1529
+ }
1530
+ }
1531
+ }
1532
+ } ,
1533
+ None =>( ) ,
1534
+ }
1535
+ }
1536
+ true
1537
+ }
1507
1538
}
0 commit comments