From 08d639ba6204a8e6633fb962822e70a90f440aae Mon Sep 17 00:00:00 2001 From: kwatch Date: Fri, 4 Oct 2024 07:25:55 +0900 Subject: [PATCH 1/2] Backport from v0.5.0 to fix a bug #74 --- lib/optparse.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index 832b928..fd7c8c5 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1641,14 +1641,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)} From aa8df14970efd13b88f6d024e49b8d0d9d03cd79 Mon Sep 17 00:00:00 2001 From: kwatch Date: Fri, 4 Oct 2024 07:26:20 +0900 Subject: [PATCH 2/2] Add new test case for bug #74 --- test/optparse/test_optparse.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/optparse/test_optparse.rb b/test/optparse/test_optparse.rb index bfa705a..dbf7f42 100644 --- a/test/optparse/test_optparse.rb +++ b/test/optparse/test_optparse.rb @@ -120,4 +120,16 @@ def test_nonopt_pattern e = assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-t))} assert_equal(["-t"], e.args) end + + def test_default_help_option # bug #74 + @opt.require_exact = true # !!! + sout, serr = capture_output() do + assert_raise(SystemExit) do + @opt.parse!(["--help"]) + end + end + assert_empty(serr) + assert_match(/\AUsage: \w+ \[options\]\n\z/, sout) + end + end pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy