@@ -425,13 +425,13 @@ def parse cmdline = ARGV
425425 end
426426
427427 if SINGLE_ARG_TYPES . include? ( opts [ :type ] )
428- unless opts [ :multi ] # single parameter
429- vals [ sym ] = vals [ sym ] [ 0 ] [ 0 ]
430- else # multiple options, each with a single parameter
428+ if opts [ :multi ] # multiple options, each with a single parameter
431429 vals [ sym ] = vals [ sym ] . map { |p | p [ 0 ] }
430+ else # single parameter
431+ vals [ sym ] = vals [ sym ] [ 0 ] [ 0 ]
432432 end
433433 elsif MULTI_ARG_TYPES . include? ( opts [ :type ] ) && !opts [ :multi ]
434- vals [ sym ] = vals [ sym ] [ 0 ] # single option, with multiple parameters
434+ vals [ sym ] = vals [ sym ] [ 0 ] # single option, with multiple parameters
435435 end
436436 # else: multiple options, with multiple parameters
437437
@@ -584,7 +584,10 @@ def each_arg args
584584 i += 1
585585 when /^--(\S +)$/ # long argument
586586 params = collect_argument_parameters ( args , i + 1 )
587- unless params . empty?
587+ if params . empty? # long argument no parameter
588+ yield args [ i ] , nil
589+ i += 1
590+ else
588591 num_params_taken = yield args [ i ] , params
589592 unless num_params_taken
590593 if @stop_on_unknown
@@ -595,16 +598,16 @@ def each_arg args
595598 end
596599 end
597600 i += 1 + num_params_taken
598- else # long argument no parameter
599- yield args [ i ] , nil
600- i += 1
601601 end
602602 when /^-(\S +)$/ # one or more short arguments
603603 shortargs = ::Regexp . last_match ( 1 ) . split ( // )
604604 shortargs . each_with_index do |a , j |
605605 if j == ( shortargs . length - 1 )
606606 params = collect_argument_parameters ( args , i + 1 )
607- unless params . empty?
607+ if params . empty? # argument no parameter
608+ yield "-#{ a } " , nil
609+ i += 1
610+ else
608611 num_params_taken = yield "-#{ a } " , params
609612 unless num_params_taken
610613 if @stop_on_unknown
@@ -615,9 +618,6 @@ def each_arg args
615618 end
616619 end
617620 i += 1 + num_params_taken
618- else # argument no parameter
619- yield "-#{ a } " , nil
620- i += 1
621621 end
622622 else
623623 yield "-#{ a } " , nil
0 commit comments