tags:

views:

82

answers:

2

I'm stuck in a totally stupid situation. When I use the snippet below, despite my command line being "./the_script.rb -s serv" and I check the value of the service variable within the code, it's always taken to be of boolean class by optparse. So I cannot get my string from the command line...

any ideas ?

opt = OptionParser.new do |opt|

 opt.on('-s','--service','twitter (tw) or identica (id)') do |val| 
   service = val.to_s 
 end

end
A: 

I think you want to call opt.parse! on the block somewhere.

Ryan Bigg
+1  A: 

I'm a Python programmer, not a Ruby one, but browsing the examples in the Ruby docs for this, I'd say the default behavior as you have it is to act as a boolean. You need to specify more parameters for it to actually store the value.

opts.on("-s", "--service [SERVICE]", [:twitter, :identica], "Select a service (Twitter or Identica)" do |service|
    options.service = service
end

Then options.service should have the designated service. I think... Hey, it's Ruby. ;-)

gotgenes
+1 from a rubyist. This is how you do it.
rampion