@@ -1398,9 +1398,21 @@ pub enum OptionKind {
13981398}
13991399
14001400pub 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.
14021408 pub name : & ' static str ,
14031409 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 ,
14041416}
14051417
14061418impl RustcOptGroup {
@@ -1409,7 +1421,13 @@ impl RustcOptGroup {
14091421 }
14101422
14111423 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+ } ;
14131431 }
14141432}
14151433
@@ -1419,31 +1437,21 @@ pub fn make_opt(
14191437 short_name : & ' static str ,
14201438 long_name : & ' static str ,
14211439 desc : & ' static str ,
1422- hint : & ' static str ,
1440+ value_hint : & ' static str ,
14231441) -> 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+ }
14241447 RustcOptGroup {
14251448 name : cmp:: max_by_key ( short_name, long_name, |s| s. len ( ) ) ,
14261449 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,
14471455 }
14481456}
14491457
0 commit comments