diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-25 22:56:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-25 22:56:15 +0000 |
commit | 2a92b1e58805fe668d854cb811dda7dfbd5dadfd (patch) | |
tree | 11481a88812b422c6b46cfcf050e2dcd87d8c44b /lib/optparse.rb | |
parent | ae982c17f0dd9c17cf3f18f5dd2e99aee1690842 (diff) |
* lib/optparse.rb (RequiredArgument#parse): not consume unmatched
argument. fixed [ruby-dev:27316]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r-- | lib/optparse.rb | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index 8fc27f8cd3..18ffe123e7 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -442,11 +442,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 @@ -467,24 +470,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 |