aboutsummaryrefslogtreecommitdiffstats
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-31 08:28:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-31 08:28:48 +0000
commita9f5602594fa3b7622090e6b3ec1d5087eb411ba (patch)
tree345b8546283f0e3556c4c458f64a8270a53cf299 /lib/optparse.rb
parentd7a9c936a6e521f87624a7fe4a62d569166386d0 (diff)
downloadruby-a9f5602594fa3b7622090e6b3ec1d5087eb411ba.tar.gz
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
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 13d4591c07..f12a5c0a54 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -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