From e13bfb15096a9d12e93055fbe6526d15bc54e20c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 31 Jan 2003 00:41:40 +0000 Subject: [PATCH] * lib/optparse.rb (OptionParser::make_switch): NoArgument doesn't override other styles. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- lib/optparse.rb | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73fc1e82b4..f30373b9e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,11 @@ -Fri Jan 31 02:50:34 2003 Nobuyoshi Nakada +Fri Jan 31 09:40:07 2003 Nobuyoshi Nakada * lib/optparse.rb (OptionParser::List::accept): default pattern must not be nil. + * lib/optparse.rb (OptionParser::make_switch): NoArgument doesn't + override other styles. + Thu Jan 30 16:46:43 2003 Nobuyoshi Nakada * lib/optparse.rb (OptionParser::Switch::PlacedArgument): added. diff --git a/lib/optparse.rb b/lib/optparse.rb index 5be91eb27d..d7434ca4f2 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -158,6 +158,10 @@ Individual switch class. raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}" end + def self.pattern + NilClass + end + =begin private --- OptionParser::Switch.new =end #'#"#`# @@ -294,6 +298,9 @@ Switch that takes no arguments. end def self.incompatible_argument_styles(*) end + def self.pattern + Object + end end =begin private @@ -336,7 +343,8 @@ Switch that can omit argument. class PlacedArgument < self def parse(arg, argv, &error) - unless arg or argv.empty? or /\A-/ =~ argv[0] + unless arg + return nil, block, nil if argv.empty? or /\A-/ =~ argv[0] arg = argv.shift end super(*parse_arg(arg, &error)) @@ -981,8 +989,8 @@ Default options, which never appear in option summary. nolong << 'no-' + o when /^--([^][=\s]*)(.+)?/ q, a = $1, $2 - o = notwice(a ? NilClass : TrueClass, klass, 'type') if a + o = notwice(NilClass, klass, 'type') default_style = default_style.guess(arg = a) default_pattern, conv = search(:atype, o) unless default_pattern end @@ -999,8 +1007,8 @@ Default options, which never appear in option summary. short << Regexp.new(q) when /^-(.)(.+)?/ q, a = $1, $2 - o = notwice((a ? Object : TrueClass), klass, 'type') if a + o = notwice(NilClass, klass, 'type') default_style = default_style.guess(arg = a) default_pattern, conv = search(:atype, o) unless default_pattern end @@ -1014,7 +1022,7 @@ Default options, which never appear in option summary. end end - default_pattern, conv = search(:atype, Object) unless default_pattern + default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern s = if short.empty? and long.empty? raise ArgumentError, "no switch given" if style or pattern or block desc