OptionParser mandatory versus optional arguments

Discussion in 'Ruby' started by byrnejb, Jul 15, 2010.

  1. byrnejb

    byrnejb Guest

    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?
    byrnejb, Jul 15, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piers Chivers
    Replies:
    2
    Views:
    392
    Piers Chivers
    Mar 2, 2004
  2. ANoobee
    Replies:
    3
    Views:
    389
  3. Thomas Wittek
    Replies:
    4
    Views:
    1,480
    Joe Kesselman
    Sep 13, 2007
  4. David Mathog
    Replies:
    23
    Views:
    622
    CBFalconer
    Aug 5, 2008
  5. Paul Butcher
    Replies:
    12
    Views:
    702
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page