Project

General

Profile

Actions

Bug #8120

closed

OptionParser is not handling lists of arguments correctly

Added by jpsember (Jeff Sember) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.2]
Backport:
[ruby-core:53517]

Description

Only the first element in a list of arguments is being processed by OptionParser. With the following program:


require 'optparse'

options = {}

optparse = OptionParser.new do |opts|
options[:list] = nil
opts.on("-l","--list x,y,z", Array, "Example") do |list|
options[:list] = list
end
end

arg = "--list a b c".split
optparse.parse(arg)
puts options

...I expect to see {:list=>["a","b","c"]} as output, but instead I get:

{:list=>["a"]}

Updated by drbrain (Eric Hodel) about 11 years ago

  • Category set to lib
  • Status changed from Open to Rejected

You must use commas and no whitespace when entering a list as in your second arguments to opts.on

Actions

Also available in: Atom PDF

Like0
Like0