OptionParser mandatory versus optional arguments

B

byrnejb

I am trying, without success obviously, to check for a mandatory
argument switch using OptionParser. I have this code:

opts.on("-m", "--mapfile=FILE",
"Set data mapping file name",
" (default) '#{options.mapfile}'") do |file|
options.mapfile << file.strip
end

As far as I can tell, the absence of [] around the argument FILE
should make this a required switch. However, when I run the script
without any switches at all it does not raise a missing argument
error. Why not?

Does 'mandatory' refer only to the value supplied to a switch and not
to the presence or absence of the switch itself?
 

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,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top