diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-02-10 22:56:32 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-02-11 00:47:41 +0900 |
commit | f960fbc10256ee227ad6887089388e0bda59aab5 () | |
tree | 0dc4070cea37de37b41866b9981cdbbd35e66dee /lib/optparse.rb | |
parent | fdd92c2d61cc8eb86b187d8f116ed640c959a62c (diff) |
[ruby/optparse] Search exactly when `require_exact`
To work with options defined as `--[no]-something`. Fix https://bugs.ruby-lang.org/issues/20252 Fix https://.com/ruby/optparse/pull/60 https://.com/ruby/optparse/commit/78afdab307
-rw-r--r-- | lib/optparse.rb | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -1054,7 +1054,7 @@ XXX # Shows option summary. # Officious['help'] = proc do |parser| - Switch::NoArgument.new(nil, nil, ["-h"], ["--help"]) do |arg| puts parser.help exit end @@ -1479,7 +1479,7 @@ XXX default_style = default_style.guess(arg = a) default_pattern, conv = search(:atype, o) unless default_pattern end - ldesc << "--#{q}" << "--no-#{q}" (o = q.downcase).tr!('_', '-') long << o not_pattern, not_conv = search(:atype, FalseClass) unless not_style @@ -1654,14 +1654,19 @@ XXX opt, rest = $1, $2 opt.tr!('_', '-') begin - sw, = complete(:long, opt, true) - if require_exact && !sw.long.include?("--#{opt}") - throw :terminate, arg unless raise_unknown - raise InvalidOption, arg end rescue ParseError throw :terminate, arg unless raise_unknown raise $!.set_option(arg, true) end begin opt, cb, *val = sw.parse(rest, argv) {|*exc| raise(*exc)} |