title: Ruby optparse Limitations
body: <p>I currently script in Python but I wish to try Ruby for several reasons. I've looked at a lot of sample code and read a lot of documentation over the last week. One point of concern I have is the lack of a proper command line argument parsing libraries in Ruby. Ruby experts, don't get mad at me — maybe I don't know. That's why I am here.</p>
  
  <p>In Python, I was used to using <code>argparse</code> which in my opinion is simply perfect (maybe for my needs). Unfortunately though, <code>OptionParser</code> doesn't allow for the flexibility and features that <code>argparse</code> does.</p>
  
  <p>I am specifically looking at the following constraints for now:</p>
  
  <ol>
  <li><p>How do I make <strong>mutually exclusive option lists</strong>? For e.g. a very small option list for a program called <code>test</code>.</p>
  
  <pre><code>usage: test [-h] [-a | -b | -c] [-d] [filename]
  </code></pre>
  
  <p>I can write some code like:</p>
  
  <pre><code># implement a ----------------------------------------------
  opts.on( "-a", "--alpha",
           "implement alpha") do
      #...
  end
  </code></pre>
  
  <p>and so on. But then, I've no way to make <code>a</code>, <code>b</code> and <code>c</code> mutually exclusive unless I code a permutation of those and do some error handling. For e.g.</p>
  
  <pre><code>test -ab #should through an error
  </code></pre>
  
  <p>In Python, I could do this in a very easy way:</p>
  
  <pre><code># create an command line argument parser object
  cmd_line_parser = argparse.ArgumentParser()
  
  # create a mutually exclusive group
  cmd_line_group = cmd_line_parser.add_mutually_exclusive_group()
  </code></pre>
  
  <ol>
  <li><p>Secondly, I've no way of pairing <code>-d</code> with <code>-a</code> unless I specifically write code for this permutation. This is insane.</p></li>
  <li><p>I've to write the <code>[OPTION]</code> list myself; I've no way to know if I am wrong or right unless and until I do a blackbox testing for all possible input permutations and map them to the blackbox list.</p></li>
  <li><p>Moreover, compulsory arguments again need to be handled using special code.</p></li>
  </ol></li>
  </ol>
  
  <p>Is there an easy of handling these constraints using <code>optparse</code> or other libraries in Ruby?</p>