@@ -1398,9 +1398,16 @@ pub enum OptionKind {
1398
1398
}
1399
1399
1400
1400
pub struct RustcOptGroup {
1401
- apply : Box < dyn Fn ( & mut getopts:: Options ) -> & mut getopts:: Options > ,
1401
+ /// Display name for this option. Normally equal to `long_name`, except for
1402
+ /// options that don't have a long name.
1402
1403
pub name : & ' static str ,
1403
1404
stability : OptionStability ,
1405
+ kind : OptionKind ,
1406
+
1407
+ short_name : & ' static str ,
1408
+ long_name : & ' static str ,
1409
+ desc : & ' static str ,
1410
+ value_hint : & ' static str ,
1404
1411
}
1405
1412
1406
1413
impl RustcOptGroup {
@@ -1409,7 +1416,13 @@ impl RustcOptGroup {
1409
1416
}
1410
1417
1411
1418
pub fn apply ( & self , options : & mut getopts:: Options ) {
1412
- ( self . apply ) ( options) ;
1419
+ let & Self { short_name, long_name, desc, value_hint, .. } = self ;
1420
+ match self . kind {
1421
+ OptionKind :: Opt => options. optopt ( short_name, long_name, desc, value_hint) ,
1422
+ OptionKind :: Multi => options. optmulti ( short_name, long_name, desc, value_hint) ,
1423
+ OptionKind :: Flag => options. optflag ( short_name, long_name, desc) ,
1424
+ OptionKind :: FlagMulti => options. optflagmulti ( short_name, long_name, desc) ,
1425
+ } ;
1413
1426
}
1414
1427
}
1415
1428
@@ -1419,31 +1432,21 @@ pub fn make_opt(
1419
1432
short_name : & ' static str ,
1420
1433
long_name : & ' static str ,
1421
1434
desc : & ' static str ,
1422
- hint : & ' static str ,
1435
+ value_hint : & ' static str ,
1423
1436
) -> RustcOptGroup {
1437
+ // "Flag" options don't have a value, and therefore don't have a value hint.
1438
+ match kind {
1439
+ OptionKind :: Opt | OptionKind :: Multi => { }
1440
+ OptionKind :: Flag | OptionKind :: FlagMulti => assert_eq ! ( value_hint, "" ) ,
1441
+ }
1424
1442
RustcOptGroup {
1425
1443
name : cmp:: max_by_key ( short_name, long_name, |s| s. len ( ) ) ,
1426
1444
stability,
1427
- apply : match kind {
1428
- OptionKind :: Opt => Box :: new ( move |opts : & mut getopts:: Options | {
1429
- opts. optopt ( short_name, long_name, desc, hint)
1430
- } ) ,
1431
- OptionKind :: Multi => Box :: new ( move |opts : & mut getopts:: Options | {
1432
- opts. optmulti ( short_name, long_name, desc, hint)
1433
- } ) ,
1434
- OptionKind :: Flag => {
1435
- assert_eq ! ( hint, "" ) ;
1436
- Box :: new ( move |opts : & mut getopts:: Options | {
1437
- opts. optflag ( short_name, long_name, desc)
1438
- } )
1439
- }
1440
- OptionKind :: FlagMulti => {
1441
- assert_eq ! ( hint, "" ) ;
1442
- Box :: new ( move |opts : & mut getopts:: Options | {
1443
- opts. optflagmulti ( short_name, long_name, desc)
1444
- } )
1445
- }
1446
- } ,
1445
+ kind,
1446
+ short_name,
1447
+ long_name,
1448
+ desc,
1449
+ value_hint,
1447
1450
}
1448
1451
}
1449
1452
0 commit comments