I use optparse in babushka. You can just #to_s it to get usage information:

https://github.com/benhoskings/babushka/blob/master/lib/babushka/cmdline/parser.rb#L33-35

—Ben


On 29/07/2011, at 11:33 AM, Sonia Hamilton wrote:

> I'm using optparse in a script, it's working. But I want a clean way
> to display the help message (that corresponds to --help) if the user
> enters an incorrect option. Any pointers on the best way to do this?
> 
>> begin
>>  olog = odebug = false
>>  OptionParser.new do |opts|
>>    opts.banner = %Q{A script to ... }
>>    opts.on("-h", "--help",  "Display this help") do
>>      puts opts
>>      exit true
>>    end
>>    opts.on("-l", "--log",   "Write logging to foo.log rather than stderr") do
>>      olog   = true
>>    end
>>    opts.on("-d", "--debug", "Also include debugging in logging") do
>>      odebug = true
>>    end
>>  end.parse!
>> rescue
>>  # I want to display "opts" here rather 
>>  # than telling user to type in -h ...
>>  puts "Unknown option. Please use -h to display options."
>>  exit false
>> end
> 
> -- 
> Sonia Hamilton

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to