* lib/optparse.rb (OptionParser#order!): call handlers iff matches

non-switch.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-04-13 13:12:24 +00:00
parent c7151a3f5e
commit 4eede6b4a1
2 changed files with 15 additions and 4 deletions

View File

@ -1,3 +1,8 @@
Wed Apr 13 22:12:16 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser#order!): call handlers iff matches
non-switch.
Wed Apr 13 21:20:35 2005 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in (mingw32): extract msvcr*.dll from objdump result.

View File

@ -417,13 +417,17 @@ class OptionParser
end
def add_banner(to)
if @short and @short.empty? and @long and @long.empty?
unless @short or @long
s = desc.join
to << " [" + s + "]..." unless s.empty?
end
to
end
def match_nonswitch?(str)
@pattern =~ str unless @short or @long
end
#
# Switch that takes no arguments.
#
@ -1211,13 +1215,13 @@ class OptionParser
if !(short.empty? and long.empty?)
s = (style || default_style).new(pattern || default_pattern,
conv, sdesc, ldesc, arg, desc, block)
elsif !block
elsif !block_given?
raise ArgumentError, "no switch given" if style or pattern
s = desc
else
short << pattern
s = (style || default_style).new(pattern,
conv, sdesc, ldesc, arg, desc, block)
conv, nil, nil, arg, desc, block)
end
return s, short, long,
(not_style.new(not_pattern, not_conv, sdesc, ldesc, nil, desc, block) if not_style),
@ -1347,8 +1351,10 @@ class OptionParser
# non-option argument
else
catch(:prune) do
require 'pp'
pp @stack
visit(:each_option) do |sw|
sw.block.call(arg) if sw.pattern and sw.pattern =~ arg
sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
end
nonopt.call(arg)
end