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

Attachment: signature.asc
Description: Digital signature

Reply via email to