Skip to content

Commit a7bf149

Browse files
committed
[ruby/optparse] Search exactly when require_exact
To work with options defined as `--[no]-something`. Fix ruby/optparse#60 ruby/optparse@c5ddf23f52
1 parent a1055c8 commit a7bf149

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

lib/optparse.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,14 +1654,19 @@ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
16541654
opt, rest = $1, $2
16551655
opt.tr!('_', '-')
16561656
begin
1657-
sw, = complete(:long, opt, true)
1658-
if require_exact && !sw.long.include?(arg)
1659-
throw :terminate, arg unless raise_unknown
1660-
raise InvalidOption, arg
1657+
if require_exact
1658+
sw, = search(:long, opt)
1659+
else
1660+
sw, = complete(:long, opt, true)
16611661
end
16621662
rescue ParseError
16631663
throw :terminate, arg unless raise_unknown
16641664
raise $!.set_option(arg, true)
1665+
else
1666+
unless sw
1667+
throw :terminate, arg unless raise_unknown
1668+
raise InvalidOption, arg
1669+
end
16651670
end
16661671
begin
16671672
opt, cb, *val = sw.parse(rest, argv) {|*exc| raise(*exc)}

0 commit comments

Comments
 (0)