I’m trying to do something that looks like this:
opt_parser = OptionParser.new do |opt|
opt.banner = "Test"
opt.separator ""
opt.on("-t", "--test arg1 arg2", "Test") do |arg1, arg2|
puts arg1
puts arg2
end
end
The problem is that it returns the arg1, but arg2 returns nil. How to make this work?
The accepted way of specifying a list of values for a given option is by repeating that option (for example the
-Doption as accepted byjavaand C compilers), e.g.In some cases, the nature of your arguments may be such that you can afford to use a separator without introducing ambiguity (for example the
-classpathoption tojavaor, more clearly, the-ooption tops), so ifarg1andarg2can never normally contain a comma,then you could also accept e.g.The code that supports both conventions above would be something along the lines of:
Then: