@@ -236,9 +236,8 @@ macro_rules! options {
236236
237237 #[ allow( non_upper_case_globals, dead_code) ]
238238 mod $mod_desc {
239- pub const parse_bool: Option <& str > = None ;
240- pub const parse_opt_bool: Option <& str > =
241- Some ( "one of: `y`, `yes`, `on`, `n`, `no`, or `off`" ) ;
239+ pub const parse_bool: Option <& str > = Some ( "one of: `y`, `yes`, `on`, `n`, `no`, or `off`" ) ;
240+ pub const parse_opt_bool: Option <& str > = parse_bool;
242241 pub const parse_string: Option <& str > = Some ( "a string" ) ;
243242 pub const parse_string_push: Option <& str > = Some ( "a string" ) ;
244243 pub const parse_pathbuf_push: Option <& str > = Some ( "a path" ) ;
@@ -310,52 +309,45 @@ macro_rules! options {
310309 }
311310 ) *
312311
313- /// Set a flag to true. Note that it cannot set the flag to false, so
314- /// using this parser in combination with a flag that defaults to true
315- /// is useless; the flag will always be true.
312+ /// Use this for any boolean option that has a static default.
316313 fn parse_bool( slot: & mut bool , v: Option <& str >) -> bool {
317314 match v {
318- Some ( ..) => false ,
319- None => { * slot = true ; true }
315+ Some ( "y" ) | Some ( "yes" ) | Some ( "on" ) | None => { * slot = true ; true }
316+ Some ( "n" ) | Some ( "no" ) | Some ( "off" ) => { * slot = false ; true }
317+ _ => false ,
320318 }
321319 }
322320
321+ /// Use this for any boolean option that lacks a static default. (The
322+ /// actions taken when such an option is not specified will depend on
323+ /// other factors, such as other options, or target options.)
323324 fn parse_opt_bool( slot: & mut Option <bool >, v: Option <& str >) -> bool {
324325 match v {
325- Some ( s) => {
326- match s {
327- "n" | "no" | "off" => {
328- * slot = Some ( false ) ;
329- }
330- "y" | "yes" | "on" => {
331- * slot = Some ( true ) ;
332- }
333- _ => { return false ; }
334- }
335-
336- true
337- } ,
338- None => { * slot = Some ( true ) ; true }
326+ Some ( "y" ) | Some ( "yes" ) | Some ( "on" ) | None => { * slot = Some ( true ) ; true }
327+ Some ( "n" ) | Some ( "no" ) | Some ( "off" ) => { * slot = Some ( false ) ; true }
328+ _ => false ,
339329 }
340330 }
341331
342- fn parse_opt_string( slot: & mut Option <String >, v: Option <& str >) -> bool {
332+ /// Use this for any string option that has a static default.
333+ fn parse_string( slot: & mut String , v: Option <& str >) -> bool {
343334 match v {
344- Some ( s) => { * slot = Some ( s. to_string( ) ) ; true } ,
335+ Some ( s) => { * slot = s. to_string( ) ; true } ,
345336 None => false ,
346337 }
347338 }
348339
349- fn parse_opt_pathbuf( slot: & mut Option <PathBuf >, v: Option <& str >) -> bool {
340+ /// Use this for any string option that lacks a static default.
341+ fn parse_opt_string( slot: & mut Option <String >, v: Option <& str >) -> bool {
350342 match v {
351- Some ( s) => { * slot = Some ( PathBuf :: from ( s ) ) ; true } ,
343+ Some ( s) => { * slot = Some ( s . to_string ( ) ) ; true } ,
352344 None => false ,
353345 }
354346 }
355347
356- fn parse_string ( slot: & mut String , v: Option <& str >) -> bool {
348+ fn parse_opt_pathbuf ( slot: & mut Option < PathBuf > , v: Option <& str >) -> bool {
357349 match v {
358- Some ( s) => { * slot = s . to_string ( ) ; true } ,
350+ Some ( s) => { * slot = Some ( PathBuf :: from ( s ) ) ; true } ,
359351 None => false ,
360352 }
361353 }
@@ -417,13 +409,15 @@ macro_rules! options {
417409 }
418410 }
419411
412+ /// Use this for any uint option that has a static default.
420413 fn parse_uint( slot: & mut usize , v: Option <& str >) -> bool {
421414 match v. and_then( |s| s. parse( ) . ok( ) ) {
422415 Some ( i) => { * slot = i; true } ,
423416 None => false
424417 }
425418 }
426419
420+ /// Use this for any uint option that lacks a static default.
427421 fn parse_opt_uint( slot: & mut Option <usize >, v: Option <& str >) -> bool {
428422 match v {
429423 Some ( s) => { * slot = s. parse( ) . ok( ) ; slot. is_some( ) }
0 commit comments