Skip to content

Commit

Permalink
[ruby/optparse] Search exactly when require_exact
Browse files Browse the repository at this point in the history
To work with options defined as `--[no]-something`.
Fix ruby/optparse#60

ruby/optparse@c5ddf23f52
  • Loading branch information
nobu committed Feb 10, 2024
1 parent a1055c8 commit a7bf149
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1654,14 +1654,19 @@ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
opt, rest = $1, $2
opt.tr!('_', '-')
begin
sw, = complete(:long, opt, true)
if require_exact && !sw.long.include?(arg)
throw :terminate, arg unless raise_unknown
raise InvalidOption, arg
if require_exact
sw, = search(:long, opt)
else
sw, = complete(:long, opt, true)
end
rescue ParseError
throw :terminate, arg unless raise_unknown
raise $!.set_option(arg, true)
else
unless sw
throw :terminate, arg unless raise_unknown
raise InvalidOption, arg
end
end
begin
opt, cb, *val = sw.parse(rest, argv) {|*exc| raise(*exc)}
Expand Down

0 comments on commit a7bf149

Please sign in to comment.