summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-02-09 12:59:43 +0900
committerNobuyoshi Nakada <[email protected]>2024-02-09 19:58:19 +0900
commit2c6767b71ef5154f49e4aef7a236849a934e68fb ()
treeb1c5946b6272ffffbca1ef097c9621f8166d392a /lib/optparse.rb
parent5e12b757162970b317e2fdf2490b694b52125743 (diff)
[ruby/optparse] Respect default values in block parameters
Fix https://.com/ruby/optparse/pull/55 https://.com/ruby/optparse/commit/9d53e74aa4
-rw-r--r--lib/optparse.rb24
1 files changed, 15 insertions, 9 deletions
@@ -697,6 +697,11 @@ class OptionParser
q.object_group(self) {pretty_print_contents(q)}
end
#
# Switch that takes no arguments.
#
@@ -755,7 +760,7 @@ class OptionParser
if arg
conv_arg(*parse_arg(arg, &error))
else
- conv_arg(arg)
end
end
@@ -774,13 +779,14 @@ class OptionParser
#
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-./ =~ (val = argv[0]))
- return nil, block, nil
end
opt = (val = parse_arg(val, &error))[1]
val = conv_arg(*val)
if opt and !arg
argv.shift
else
val[0] = nil
end
val
@@ -1633,7 +1639,7 @@ XXX
# Non-option arguments remain in +argv+.
#
def order!(argv = default_argv, into: nil, &nonopt)
- setter = ->(name, val) {into[name.to_sym] = val} if into
parse_in_order(argv, setter, &nonopt)
end
@@ -1658,9 +1664,9 @@ XXX
raise $!.set_option(arg, true)
end
begin
- opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
- val = cb.call(val) if cb
- setter.call(sw.switch_name, val) if setter
rescue ParseError
raise $!.set_option(arg, rest)
end
@@ -1690,7 +1696,7 @@ XXX
raise $!.set_option(arg, true)
end
begin
- opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
rescue ParseError
raise $!.set_option(arg, arg.length > 2)
else
@@ -1698,8 +1704,8 @@ XXX
end
begin
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
- val = cb.call(val) if cb
- setter.call(sw.switch_name, val) if setter
rescue ParseError
raise $!.set_option(arg, arg.length > 2)
end