@@ -236,9 +236,8 @@ macro_rules! options {
236
236
237
237
#[ allow( non_upper_case_globals, dead_code) ]
238
238
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;
242
241
pub const parse_string: Option <& str > = Some ( "a string" ) ;
243
242
pub const parse_string_push: Option <& str > = Some ( "a string" ) ;
244
243
pub const parse_pathbuf_push: Option <& str > = Some ( "a path" ) ;
@@ -310,52 +309,45 @@ macro_rules! options {
310
309
}
311
310
) *
312
311
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.
316
313
fn parse_bool( slot: & mut bool , v: Option <& str >) -> bool {
317
314
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 ,
320
318
}
321
319
}
322
320
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.)
323
324
fn parse_opt_bool( slot: & mut Option <bool >, v: Option <& str >) -> bool {
324
325
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 ,
339
329
}
340
330
}
341
331
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 {
343
334
match v {
344
- Some ( s) => { * slot = Some ( s. to_string( ) ) ; true } ,
335
+ Some ( s) => { * slot = s. to_string( ) ; true } ,
345
336
None => false ,
346
337
}
347
338
}
348
339
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 {
350
342
match v {
351
- Some ( s) => { * slot = Some ( PathBuf :: from ( s ) ) ; true } ,
343
+ Some ( s) => { * slot = Some ( s . to_string ( ) ) ; true } ,
352
344
None => false ,
353
345
}
354
346
}
355
347
356
- fn parse_string ( slot: & mut String , v: Option <& str >) -> bool {
348
+ fn parse_opt_pathbuf ( slot: & mut Option < PathBuf > , v: Option <& str >) -> bool {
357
349
match v {
358
- Some ( s) => { * slot = s . to_string ( ) ; true } ,
350
+ Some ( s) => { * slot = Some ( PathBuf :: from ( s ) ) ; true } ,
359
351
None => false ,
360
352
}
361
353
}
@@ -417,13 +409,15 @@ macro_rules! options {
417
409
}
418
410
}
419
411
412
+ /// Use this for any uint option that has a static default.
420
413
fn parse_uint( slot: & mut usize , v: Option <& str >) -> bool {
421
414
match v. and_then( |s| s. parse( ) . ok( ) ) {
422
415
Some ( i) => { * slot = i; true } ,
423
416
None => false
424
417
}
425
418
}
426
419
420
+ /// Use this for any uint option that lacks a static default.
427
421
fn parse_opt_uint( slot: & mut Option <usize >, v: Option <& str >) -> bool {
428
422
match v {
429
423
Some ( s) => { * slot = s. parse( ) . ok( ) ; slot. is_some( ) }
0 commit comments