Gem and optparse : help needed

Hello, I want to use optparse on a gem packaged bin/ file
(eg/usr/lib/ruby/gems/1.8/gems/mypackage/bin/foo)

The goal is to make foo usable from the command line without anything
else except the name of the file (no .rb, no ruby ./something)
So, the Ruby file in bin/ directory don’t have .rb extension and
includes this as the first line of code
#!/usr/bin/ruby

So does several packages I’ve seen (rcov for example)

But for a reason I don’t understand the code above doesn’t works…
From the stdlib doc, tested on a mygem/bin/foo :

#!/usr/bin/ruby
require ‘optparse’

options = {}
OptionParser.new do |opts|
opts.banner = “Usage: example.rb [options]”

 opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
   options[:verbose] = v
 end

end.parse!

p options
p ARGV

foo --verbose
displays
{}
[]

Why ? What’s wrong ??

Thanks

Hi,

At Fri, 27 Oct 2006 07:30:34 +0900,
Zouplaz wrote in [ruby-talk:222142]:

foo --verbose
displays
{}
[]

It did display {:verbose=>true} as expected.

Does gem’s wrapper do something wicked?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs