[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gem and optparse : help needed

user@domain.invalid

10/26/2006 10:26:00 PM

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
1 Answer

Nobuyoshi Nakada

10/30/2006 2:21:00 PM

0

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?

--
Nobu Nakada