[ruby/optparse] Fix parsing array arguments with :into option

19700e96d8
This commit is contained in:
fatkodima 2024-08-05 05:28:01 +03:00 committed by git
parent cbc40bb130
commit a35d324862
3 changed files with 23 additions and 6 deletions

View file

@ -1729,9 +1729,9 @@ XXX
end
end
begin
opt, cb, *val = sw.parse(rest, argv) {|*exc| raise(*exc)}
val = callback!(cb, 1, *val) if cb
callback!(setter, 2, sw.switch_name, *val) if setter
opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
val = callback!(cb, 1, val) if cb
callback!(setter, 2, sw.switch_name, val) if setter
rescue ParseError
raise $!.set_option(arg, rest)
end
@ -1761,7 +1761,7 @@ XXX
raise $!.set_option(arg, true)
end
begin
opt, cb, *val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
rescue ParseError
raise $!.set_option(arg, arg.length > 2)
else
@ -1769,8 +1769,8 @@ XXX
end
begin
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
val = callback!(cb, 1, *val) if cb
callback!(setter, 2, sw.switch_name, *val) if setter
val = callback!(cb, 1, val) if cb
callback!(setter, 2, sw.switch_name, val) if setter
rescue ParseError
raise $!.set_option(arg, arg.length > 2)
end
@ -1798,6 +1798,8 @@ XXX
# Calls callback with _val_.
def callback!(cb, max_arity, *args) # :nodoc:
args.compact!
if (size = args.size) < max_arity and cb.to_proc.lambda?
(arity = cb.arity) < 0 and arity = (1-arity)
arity = max_arity if arity > max_arity