title: Argparse groups in
body: <p>Using python's argparse module I want to pass parameters to prog two ways:</p>
  
  <p>Method 1:</p>
  
  <pre><code>./filter.py filename --start_regex "^FOO" --end_regex "BAR$" --contains "XXX" --bunch_of_common_options
  </code></pre>
  
  <p>Method 2:</p>
  
  <p><code>./filter.py filename --type "FOO_BAR_XXX" --bunch_of_common_options</code></p>
  
  <p>Logically both are doing exactly the same, because there is a dict in <code>filter.py</code> that translates "FOO_BAR_XXX" type from method 2 to appropriate options for method 1.</p>
  
  <p>I want to specify that, given:</p>
  
  <blockquote>
    <p>groupA = (--start_regex, --end_regex --contains)</p>
    
    <p>groupB = (--type)</p>
  </blockquote>
  
  <p>groupA and groupB are:</p>
  
  <ol>
  <li>mutually exclusive, and </li>
  <li>groupA must have at least start_regex
  defined</li>
  </ol>
  
  <p>Now, I'm aware of <a href="http://docs.python.org/2/library/argparse.html#mutual-exclusion" rel="nofollow noreferrer">mutually_exclusive_group</a> functionality, but it works only on single arguments (not groups of options), and <a href="http://docs.python.org/2/library/argparse.html#sub-commands" rel="nofollow noreferrer">sub-commands</a>, but it looks like I would have to have some kind of dispatch option after prog.py, like "git clone --help", or "git push --help" (<a href="https://stackoverflow.com/questions/17909294/python-argparse-mutual-exclusive-group">this</a> post proves that)</p>
  
  <p>Note that it's not elegant to say:</p>
  
  <pre><code>./filter.py with_type filename --type TYPE1
  ./filter.py without_type filename --start_regex "^FOO" --end_regex "BAR$" --contains "XXX" 
  </code></pre>
  
  <p>Or am I missing something?</p>