summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-13 13:12:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-13 13:12:24 +0000
commit4eede6b4a1aa7e6eea390c9ce82c0a5edd34fc9c (patch)
treec551c64c2cfcd83527078c9272219666260b9d49 /lib/optparse.rb
parentc7151a3f5e8fbcba2927cd382e8f4083c9b445c7 (diff)
* 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
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index f17baaf103..765344adb7 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -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