@@ -1398,9 +1398,21 @@ pub enum OptionKind {
1398
1398
}
1399
1399
1400
1400
pub struct RustcOptGroup {
1401
- apply : Box < dyn Fn ( & mut getopts:: Options ) -> & mut getopts:: Options > ,
1401
+ /// The "primary" name for this option. Normally equal to `long_name`,
1402
+ /// except for options that don't have a long name, in which case
1403
+ /// `short_name` is used.
1404
+ ///
1405
+ /// This is needed when interacting with `getopts` in some situations,
1406
+ /// because if an option has both forms, that library treats the long name
1407
+ /// as primary and the short name as an alias.
1402
1408
pub name : & ' static str ,
1403
1409
stability : OptionStability ,
1410
+ kind : OptionKind ,
1411
+
1412
+ short_name : & ' static str ,
1413
+ long_name : & ' static str ,
1414
+ desc : & ' static str ,
1415
+ value_hint : & ' static str ,
1404
1416
}
1405
1417
1406
1418
impl RustcOptGroup {
@@ -1409,7 +1421,13 @@ impl RustcOptGroup {
1409
1421
}
1410
1422
1411
1423
pub fn apply ( & self , options : & mut getopts:: Options ) {
1412
- ( self . apply ) ( options) ;
1424
+ let & Self { short_name, long_name, desc, value_hint, .. } = self ;
1425
+ match self . kind {
1426
+ OptionKind :: Opt => options. optopt ( short_name, long_name, desc, value_hint) ,
1427
+ OptionKind :: Multi => options. optmulti ( short_name, long_name, desc, value_hint) ,
1428
+ OptionKind :: Flag => options. optflag ( short_name, long_name, desc) ,
1429
+ OptionKind :: FlagMulti => options. optflagmulti ( short_name, long_name, desc) ,
1430
+ } ;
1413
1431
}
1414
1432
}
1415
1433
@@ -1419,31 +1437,21 @@ pub fn make_opt(
1419
1437
short_name : & ' static str ,
1420
1438
long_name : & ' static str ,
1421
1439
desc : & ' static str ,
1422
- hint : & ' static str ,
1440
+ value_hint : & ' static str ,
1423
1441
) -> RustcOptGroup {
1442
+ // "Flag" options don't have a value, and therefore don't have a value hint.
1443
+ match kind {
1444
+ OptionKind :: Opt | OptionKind :: Multi => { }
1445
+ OptionKind :: Flag | OptionKind :: FlagMulti => assert_eq ! ( value_hint, "" ) ,
1446
+ }
1424
1447
RustcOptGroup {
1425
1448
name : cmp:: max_by_key ( short_name, long_name, |s| s. len ( ) ) ,
1426
1449
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
- } ,
1450
+ kind,
1451
+ short_name,
1452
+ long_name,
1453
+ desc,
1454
+ value_hint,
1447
1455
}
1448
1456
}
1449
1457
0 commit comments