title: Python dependencies between groups using argparse
body: <p>I started to learn Python, and now I'm learning the great benefits of <code>argparse</code>.
  Using <code>argparse</code>, I have created two groups of arguments: <code>group_list</code> and <code>group_simulate</code>. Each of the groups has its own arguments -- the user can specify only one argument in each group (achieved using <code>parser.add_mutually_exclusive_group()</code>).</p>
  
  <p>And now my target is present a syntax error if the user specified arguments from both groupgs and not from only one of them -- I want to achieve this by using the capabilities of <code>argparse</code> and not by writing a method that asks if this and this was specified print syntax error.</p>
  
  <pre><code>import argparse
  parser = argparse.ArgumentParser(
          description='this is the description',
          epilog="This is the epilog",
          argument_default=argparse.SUPPRESS  
          )
  
  parser.add_argument('-v', '--verbose', help='verbose', action='store_true', default=False)
  
  group_list = parser.add_mutually_exclusive_group()
  group_list.add_argument('-m', help='list only modules', action='store_const', dest='list', const='modules', default='all')
  group_list.add_argument('-p', help='list only ports', action='store_const', dest='list', const='ports', default='all')
  group_list.add_argument('--list', help='list only module or ports', choices=['modules','ports'], metavar='&lt;modules/ports&gt;', default='all')
  
  group_simulate = parser.add_mutually_exclusive_group()
  group_simulate.add_argument('-M', help='simulate module down', nargs=1, metavar='module_name', dest='simulate')
  group_simulate.add_argument('-P', help='simulate FC port down', nargs=1, metavar='fc_port_name', dest='simulate')
  group_simulate.add_argument('-I', help='simulate iSCSI port down', nargs=1, metavar='iSCSI_port_name', dest='simulate')
  group_simulate.add_argument('--simulate', help='simulate module or port down', nargs=1, dest='simulate')
  
  args = parser.parse_args()
  
  print args
  </code></pre>
  
  <p>So talking more specifically:</p>
  
  <p>allowed:</p>
  
  <pre><code>test.py
  output: Namespace(list='all', verbose=False)
  test.py -m
  output: Namespace(list='modules', verbose=False)
  test.py -P asfasf
  output: Namespace(P=['asfasf'], list='all', verbose=False)
  </code></pre>
  
  <p>not allowed:</p>
  
  <pre><code>test.py -m -P asfsaf
  expected output: &lt;the help message&gt;
  test.py -P asfasf -m
  expected output: &lt;the help message&gt;
  </code></pre>
  
  <p>I have tried to achieve the wanted target with the option of <code>add_subparsers</code> from <code>argparse</code> but without any success.</p>
  
  <p>So my question is how to achieve this situation?</p>