1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

optparse.rb: fix char class option

* lib/optparse.rb (OptionParser::Completion.candidate): get rid of
  nil as key names.  [ruby-core:75773] [Bug #12438]
* lib/optparse.rb (OptionParser#make_switch): char class option
  cannot be NoArgument, default to RequiredArgument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-05-31 08:28:48 +00:00
parent e82df08b9f
commit dd1be236d9
3 changed files with 33 additions and 1 deletions

View file

@ -1,3 +1,11 @@
Tue May 31 17:28:46 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser::Completion.candidate): get rid of
nil as key names. [ruby-core:75773] [Bug #12438]
* lib/optparse.rb (OptionParser#make_switch): char class option
cannot be NoArgument, default to RequiredArgument.
Tue May 31 00:30:11 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr

View file

@ -413,7 +413,7 @@ class OptionParser
candidates = []
block.call do |k, *v|
(if Regexp === k
kn = nil
kn = "".freeze
k === key
else
kn = defined?(k.id2name) ? k.id2name : k
@ -1336,6 +1336,7 @@ XXX
default_pattern = nil
klass = nil
q, a = nil
has_arg = false
opts.each do |o|
# argument class
@ -1414,6 +1415,8 @@ XXX
if a
default_style = default_style.guess(arg = a)
default_pattern, conv = search(:atype, o) unless default_pattern
else
has_arg = true
end
sdesc << "-#{q}"
short << Regexp.new(q)
@ -1436,6 +1439,9 @@ XXX
default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
if !(short.empty? and long.empty?)
if has_arg and default_style == Switch::NoArgument
default_style = Switch::RequiredArgument
end
s = (style || default_style).new(pattern || default_pattern,
conv, sdesc, ldesc, arg, desc, block)
elsif !block

View file

@ -0,0 +1,18 @@
# frozen_string_literal: false
require_relative 'test_optparse'
class TestOptionParser::CClass < TestOptionParser
def test_no_argument
flags = []
@opt.def_option("-[a-z]") {|x| flags << x}
no_error {@opt.parse!(%w"-a")}
assert_equal(%w"a", flags)
end
def test_required_argument
flags = []
@opt.def_option("-[a-z]X") {|x| flags << x}
no_error {@opt.parse!(%w"-a")}
assert_equal(%w"a", flags)
end
end