lib/slop/parser.rb in slop-4.3.0 vs lib/slop/parser.rb in slop-4.4.0
- old
+ new
@@ -41,29 +41,37 @@
# otherwise it'll only be used as an argument.
pairs << [strings.last, nil]
@arguments = strings.dup
- pairs.each do |flag, arg|
+ pairs.each_with_index do |pair, idx|
+ flag, arg = pair
break if !flag
# ignore everything after '--', flag or not
if flag == '--'
arguments.delete(flag)
break
end
# support `foo=bar`
orig_flag = flag.dup
+ orig_arg = arg
if flag.include?("=")
flag, arg = flag.split("=")
end
if opt = try_process(flag, arg)
# since the option was parsed, we remove it from our
# arguments (plus the arg if necessary)
# delete argument first while we can find its index.
if opt.expects_argument?
+
+ # if we consumed the argument, remove the next pair
+ if orig_arg == opt.value.to_s
+ pairs.delete_at(idx + 1)
+ end
+
arguments.each_with_index do |argument, i|
if argument == orig_flag && !orig_flag.include?("=")
arguments.delete_at(i + 1)
end
end