* 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
This commit is contained in:
nobu 2005-09-25 22:56:15 +00:00
parent 977176d702
commit cd5a5a30c0
2 changed files with 16 additions and 15 deletions

View File

@ -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> Sun Sep 25 12:02:04 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb: typo fixed. * bin/erb: typo fixed.

View File

@ -454,11 +454,14 @@ class OptionParser
# Raises an exception if argument is not present. # Raises an exception if argument is not present.
# #
def parse(arg, argv, &error) def parse(arg, argv, &error)
unless arg opt = (val = parse_arg(val, &error))[1]
raise MissingArgument if argv.empty? val = conv_arg(*val)
arg = argv.shift if opt and !arg
argv.shift
else
val[0] = nil
end end
conv_arg(*parse_arg(arg, &error)) val
end end
end end
@ -479,24 +482,17 @@ class OptionParser
end 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) def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0])) if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil return nil, block, nil
end end
opt = (val = parse_arg(val, &error))[1] super
val = conv_arg(*val)
if opt and !arg
argv.shift
else
val[0] = nil
end
val
end end
end end
end end