confuse with OptionParser -h opinion

Z

Zhenning Guan

require 'optparse'

options = {}

optparse = OptionParser.new do|opts|
opts.banner = "Usage: file1 file2 ..."
opts.on( '-r', '--hhhh', 'screen' ) do
puts opts
end

opts.on( '-s', '--ssss', 'Display this screen' ) do
puts opts
end

opts.parse!
end

=======
ning@ning:~$ ruby xb.rb -h
Usage: file1 file2 ...
-r, --hhhh screen
-s, --ssss Display this screen
=======
I use -h opinion, then it put out all opinion. but -h opinion doesn't
exit.
why this happened? can someone penlight me?
 
R

Robert Klemme

2009/10/12 Zhenning Guan said:
require 'optparse'

options =3D {}

optparse =3D OptionParser.new do|opts|
=A0opts.banner =3D "Usage: file1 file2 ..."
=A0opts.on( '-r', '--hhhh', 'screen' ) do
=A0 =A0puts opts
=A0end

=A0opts.on( '-s', '--ssss', 'Display this screen' ) do
=A0 =A0puts opts
=A0end

=A0opts.parse!
end

=3D=3D=3D=3D=3D=3D=3D
ning@ning:~$ ruby xb.rb -h
Usage: file1 file2 ...
=A0 =A0-r, --hhhh =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 screen
=A0 =A0-s, --ssss =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Display thi= s screen
=3D=3D=3D=3D=3D=3D=3D
I use -h opinion, then it put out all opinion. but -h opinion doesn't
exit.
why this happened? can someone penlight me?

Someone else defined it for you

11:17:16 desktop$ ruby19 -r optparse -e ' OptionParser.new.parse "-h"'
Usage: -e [options]
11:17:42 desktop$ ruby19 -r optparse -e ' OptionParser.new.parse "-x"'
-e:1:in `<main>': invalid option: -x (OptionParser::InvalidOption)

Kind regards

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top