summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-25 22:56:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-25 22:56:15 +0000
commitcd5a5a30c026d898a5637bbc1897b71ba7302437 (patch)
tree641f709a369f3f77df9ac89d0f9e4c52d6148a3d
parent977176d702da8ce0317285f4449c795d277c2d09 (diff)
* lib/optparse.rb (RequiredArgument#parse): not consume unmatched
argument. fixed [ruby-dev:27316] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/optparse.rb26
2 files changed, 16 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index d71fdc818d..f5060ca48f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Sep 26 07:55:06 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (RequiredArgument#parse): not consume unmatched
+ argument. fixed [ruby-dev:27316]
+
Sun Sep 25 12:02:04 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb: typo fixed.
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 21d07c4665..7135c79b34 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -454,11 +454,14 @@ class OptionParser
# Raises an exception if argument is not present.
#
def parse(arg, argv, &error)
- unless arg
- raise MissingArgument if argv.empty?
- arg = argv.shift
+ opt = (val = parse_arg(val, &error))[1]
+ val = conv_arg(*val)
+ if opt and !arg
+ argv.shift
+ else
+ val[0] = nil
end
- conv_arg(*parse_arg(arg, &error))
+ val
end
end
@@ -479,24 +482,17 @@ class OptionParser
end
#
- # ?
+ # Switch that takes an argument, which does not begin with '-'.
#
- class PlacedArgument < self
+ class PlacedArgument < RequiredArgument
#
- # ?
+ # Returns nil if argument is not present or begins with '-'.
#
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil
end
- opt = (val = parse_arg(val, &error))[1]
- val = conv_arg(*val)
- if opt and !arg
- argv.shift
- else
- val[0] = nil
- end
- val
+ super
end
end
end