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