From a7bf149f0deed306e5b6600ec0f31e1dfe3da4c4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 10 Feb 2024 23:12:40 +0900 Subject: [PATCH] [ruby/optparse] Search exactly when `require_exact` To work with options defined as `--[no]-something`. Fix https://github.com/ruby/optparse/pull/60 https://github.com/ruby/optparse/commit/c5ddf23f52 --- lib/optparse.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index f145be311e8c0d..8382364977ae8a 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -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)}