# Mandatory options with optparse

**URL:** <https://www.ruby-forum.com/t/mandatory-options-with-optparse/66834>\
**Category:** Ruby\
**Created:** [August 29, 2006, 6:07pm UTC](https://www.ruby-forum.com/t/mandatory-options-with-optparse/66834 "2006-08-29T18:07:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imobach\_SSiso-8859](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e57/32.png) [@Imobach\_SSiso-8859](https://www.ruby-forum.com/u/Imobach_SSiso-8859)\
**Post date:** [August 29, 2006, 6:07pm UTC](https://www.ruby-forum.com/t/mandatory-options-with-optparse/66834/1 "2006-08-29T18:07:46Z")

</div>

Hi all,

I was playing with optparse (great stuff ;)) and I didn’t see how to  
check if  
a mandatory option have been supplied (note that I say mandatory  
_option_,  
not mandatory _argument_).

So, if I got the next chunk of code:

opts = OptionParser.new do |opts|  
opts.banner = “My silly example”

opts.on("-m", “–message MESSAGE”, “A message to show”) do |m|  
options.message = m  
end  
end

I figured out that I’d must check it by my own (if  
options.message.nil?..),  
but I only wanna know if there’s a “optparse-way”.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Imobach\_SSiso-8859](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e57/32.png) [@Imobach\_SSiso-8859](https://www.ruby-forum.com/u/Imobach_SSiso-8859)\
**Post date:** [August 31, 2006, 4:06am UTC](https://www.ruby-forum.com/t/mandatory-options-with-optparse/66834/2 "2006-08-31T04:06:45Z")

</div>

Hi,

At Wed, 30 Aug 2006 01:06:20 +0900,  
Imobach González Sosa wrote in [ruby-talk:211331]:

> I figured out that I’d must check it by my own (if options.message.nil?..),  
> but I only wanna know if there’s a “optparse-way”.

There is no suck way. I had thought about the idea like it  
formerly, but concluded that it’s easy to read and write in  
ruby, rather than in mini-DSL.
