@@ -372,7 +372,7 @@ impl Options {
372
372
free. extend ( args) ;
373
373
break ;
374
374
} else {
375
- let mut names ;
375
+ let mut name = None ;
376
376
let mut i_arg = None ;
377
377
let mut was_long = true ;
378
378
if cur. as_bytes ( ) [ 1 ] == b'-' || self . long_only {
@@ -383,57 +383,53 @@ impl Options {
383
383
& cur[ 1 ..]
384
384
} ;
385
385
let mut parts = tail. splitn ( 2 , '=' ) ;
386
- names = vec ! [ Name :: from_str( parts. next( ) . unwrap( ) ) ] ;
386
+ name = Some ( Name :: from_str ( parts. next ( ) . unwrap ( ) ) ) ;
387
387
if let Some ( rest) = parts. next ( ) {
388
388
i_arg = Some ( rest. to_string ( ) ) ;
389
389
}
390
390
} else {
391
391
was_long = false ;
392
- names = Vec :: new ( ) ;
393
392
for ( j, ch) in cur. char_indices ( ) . skip ( 1 ) {
394
393
let opt = Short ( ch) ;
395
394
396
- /* In a series of potential options (eg. -aheJ), if we
397
- see one which takes an argument, we assume all
398
- subsequent characters make up the argument. This
399
- allows options such as -L/usr/local/lib/foo to be
400
- interpreted correctly
401
- */
402
-
403
395
let opt_id = match find_opt ( & opts, & opt) {
404
396
Some ( id) => id,
405
397
None => return Err ( UnrecognizedOption ( opt. to_string ( ) ) ) ,
406
398
} ;
407
399
408
- names. push ( opt) ;
409
-
400
+ // In a series of potential options (eg. -aheJ), if we
401
+ // see one which takes an argument, we assume all
402
+ // subsequent characters make up the argument. This
403
+ // allows options such as -L/usr/local/lib/foo to be
404
+ // interpreted correctly
410
405
let arg_follows = match opts[ opt_id] . hasarg {
411
406
Yes | Maybe => true ,
412
407
No => false ,
413
408
} ;
414
409
415
410
if arg_follows {
411
+ name = Some ( opt) ;
416
412
let next = j + ch. len_utf8 ( ) ;
417
413
if next < cur. len ( ) {
418
414
i_arg = Some ( cur[ next..] . to_string ( ) ) ;
419
415
break ;
420
416
}
417
+ } else {
418
+ vals[ opt_id] . push ( ( arg_pos, Given ) ) ;
421
419
}
422
420
}
423
421
}
424
- let mut name_pos = 0 ;
425
- for nm in names. iter ( ) {
426
- name_pos += 1 ;
427
- let optid = match find_opt ( & opts, & nm) {
422
+ if let Some ( nm) = name {
423
+ let opt_id = match find_opt ( & opts, & nm) {
428
424
Some ( id) => id,
429
425
None => return Err ( UnrecognizedOption ( nm. to_string ( ) ) ) ,
430
426
} ;
431
- match opts[ optid ] . hasarg {
427
+ match opts[ opt_id ] . hasarg {
432
428
No => {
433
- if name_pos == names . len ( ) && i_arg. is_some ( ) {
429
+ if i_arg. is_some ( ) {
434
430
return Err ( UnexpectedArgument ( nm. to_string ( ) ) ) ;
435
431
}
436
- vals[ optid ] . push ( ( arg_pos, Given ) ) ;
432
+ vals[ opt_id ] . push ( ( arg_pos, Given ) ) ;
437
433
}
438
434
Maybe => {
439
435
// Note that here we do not handle `--arg value`.
@@ -443,21 +439,20 @@ impl Options {
443
439
// option at the end of the arguments when
444
440
// FloatingFrees is in use.
445
441
if let Some ( i_arg) = i_arg. take ( ) {
446
- vals[ optid ] . push ( ( arg_pos, Val ( i_arg) ) ) ;
442
+ vals[ opt_id ] . push ( ( arg_pos, Val ( i_arg) ) ) ;
447
443
} else if was_long
448
- || name_pos < names. len ( )
449
444
|| args. peek ( ) . map_or ( true , |n| is_arg ( & n) )
450
445
{
451
- vals[ optid ] . push ( ( arg_pos, Given ) ) ;
446
+ vals[ opt_id ] . push ( ( arg_pos, Given ) ) ;
452
447
} else {
453
- vals[ optid ] . push ( ( arg_pos, Val ( args. next ( ) . unwrap ( ) ) ) ) ;
448
+ vals[ opt_id ] . push ( ( arg_pos, Val ( args. next ( ) . unwrap ( ) ) ) ) ;
454
449
}
455
450
}
456
451
Yes => {
457
452
if let Some ( i_arg) = i_arg. take ( ) {
458
- vals[ optid ] . push ( ( arg_pos, Val ( i_arg) ) ) ;
453
+ vals[ opt_id ] . push ( ( arg_pos, Val ( i_arg) ) ) ;
459
454
} else if let Some ( n) = args. next ( ) {
460
- vals[ optid ] . push ( ( arg_pos, Val ( n) ) ) ;
455
+ vals[ opt_id ] . push ( ( arg_pos, Val ( n) ) ) ;
461
456
} else {
462
457
return Err ( ArgumentMissing ( nm. to_string ( ) ) ) ;
463
458
}
0 commit comments