title: Python argparse mutually exclusive with optional arguments
body: <p>My requirement is to achieve following with argparse:</p>
  
  <pre><code>script.py &lt;command&gt; (-a|--first-name [--middle-name] [--last-name])
  </code></pre>
  
  <p>So basically, the script would accept one mandatory parameter , which can have different values. And then another parameter which should either be -a or --first-name.
  Then first-name can have further parameters.</p>
  
  <p>I was exploring subparsers and mutually exclusive group, but can't figure out how to achieve this</p>
  
  <p>One crude way I am handling this is</p>
  
  <pre><code>parser = argparse.ArgumentParser(prog='myscript', usage='%(prog)s &lt;command&gt; (-a|--first-name [--middle-name] [--last-name])')
  parser.add_argument('command')
  
  mxgroup = parser.add_mutually_exclusive_group(required=True)
  mxgroup.add_argument('-a', action='store_true', help='Choose all')
  mxgroup.add_argument('--first-name', dest='fname')
  
  parser.add_argument('--middle-name', dest='mname')
  parser.add_argument('--last-name', dest='lname')
  
  args = parser.parse_args()
  
  if (args.mname or args.lname) and not args.fname:
      parser.error('middle and last names may be specified with first name only')
  </code></pre>
  
  <p>But I am thinking if these checks can be handled by argparse inherently then I won't have to redo it as the script grows</p>
  
  <p>Any help would be much appreciated</p>