# OptionParser mandatory versus optional arguments

**URL:** <https://www.ruby-forum.com/t/optionparser-mandatory-versus-optional-arguments/191641>\
**Category:** Ruby\
**Created:** [July 15, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/optionparser-mandatory-versus-optional-arguments/191641 "2010-07-15T18:23:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 15, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/optionparser-mandatory-versus-optional-arguments/191641/1 "2010-07-15T18:23:26Z")

</div>

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?
