Peña, Botp
4/5/2005 6:54:00 AM
Hi,
OptParse is great to use and its opt#on is neatly structured.
I have not perused the internals of optparse and have just taken a look at
the supposedly complete example under optparse.
i have quick qs though:
1. Can optparse capture nil/empty args?
eg.
C:\family\ruby\optparse>op
C:\family\ruby\optparse>
Of course i can capture empty args. What i want is to include the capture in
optparse structure; something like:
....
opts = OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.separator ""
opts.separator "Specific options:"
# just empty, no options/arguments.
opts.Empty_ARG do
# do something here
# <== btw, i'd like to display the banner above here, how?
end
.....
2. Can optparse capture a simple arg?
eg.
C:\family\ruby\optparse>op sampleFile
C:\family\ruby\optparse>
Of course we can capture single/simple arguments but again, what i want is
to include it in optparse structure; something like:
....
# just an argument, no option here.
opts.simple_ARG do |xarg| #pass the arg
# do something here
# maybe i default it to an option like
# -f xarg
end
.....
3. Can optparse capture errors like invalid options or invalid arguments?
eg.
C:\family\ruby\optparse>op -Z nosuchZoption
C:\family\ruby\optparse>op --delay abc
I can capture errors thru rescue but again, what i want is to include it in
optparse structure; something like:
....
opts.Error do |x| # pass the error here
case x
when OptionParser::InvalidOption
#....
when OptionParser::InvalidArgument
#.....
else
end #case
#exit
end #opts
.....
That is all for now.
Thanks to optparse authors/documentor Nobu and Gavin.
thanks and kind regards -botp
btw, s/want/wish/gi. sometimes, my english too harsh.