diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | lib/optparse.rb | 8 | ||||
-rw-r--r-- | test/optparse/test_cclass.rb | 18 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 34 insertions, 2 deletions
@@ -1,3 +1,11 @@ +Fri Jun 10 17:48:51 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. + Fri Jun 10 17:44:59 2016 NARUSE, Yui <naruse@ruby-lang.org> * re.c (unescape_nonascii): scan hex up to only 3 characters. diff --git a/lib/optparse.rb b/lib/optparse.rb index 4ec891e3ae..4f7d7c899d 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -268,7 +268,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 @@ -1191,6 +1191,7 @@ XXX default_pattern = nil klass = nil q, a = nil + has_arg = false opts.each do |o| # argument class @@ -1269,6 +1270,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) @@ -1291,6 +1294,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 diff --git a/test/optparse/test_cclass.rb b/test/optparse/test_cclass.rb new file mode 100644 index 0000000000..ac46f46bb2 --- /dev/null +++ b/test/optparse/test_cclass.rb @@ -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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-06-10" -#define RUBY_PATCHLEVEL 337 +#define RUBY_PATCHLEVEL 338 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 6 |