views:

69

answers:

1

I'd like to be able to support something like this when running my script from the command line:

script.rb -n 2 -t first.txt -t second.txt

I'd like to be able to take 1 or more t switches, but I have no clue how to achieve this. I would like to not have to do this:

script.rb -n 2 -tfirst.txt,second.txt

Got any ideas?

+6  A: 

You might want to use OptionParser http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html

Would something like this work ?

require 'optparse'
files = []

OptionParser.new do |opts|
  opts.on("-t", "--text-file TEXTFILE","Text file to run against" ) do |text_file_name|
   files << text_file_name
  end
end.parse!

puts files.inspect
phtrivier
It worked great! Thank you.
Geo