title: How to use argparse subparsers correctly?
body: <p>I've been searching through a lot of the subparser examples on here and in general but can't seem to figure this seemingly simple thing out.</p>
  <p>I have two var types of which one has constraints so thought subparser was the way to go. e.g. -t allows for either &quot;A&quot; or &quot;B&quot;. If the user passes &quot;A&quot; then they are further required to also specify if it is either &quot;a1&quot; or &quot;a2&quot;. If they pass just &quot;B&quot; then nothing.</p>
  <p>Can I do this and have argparse return me what type of &quot;A&quot; was passed or if it was just &quot;B&quot;?</p>
  <p>The below seems to work but for some reason breaks when passing anything after the subparse.</p>
  <p>e.g. from a linux terminal</p>
  <pre><code>&gt;&gt; python test01.py -t A a1 -v 61
  </code></pre>
  <p>errors with...</p>
  <pre><code>usage: test01.py a1 [-h]
  test01.py a1: error: unrecognized arguments: -v
  </code></pre>
  <p>Hopefully that makes sense.</p>
  <p>The code:</p>
  <pre><code>import argparse
  
  parser = argparse.ArgumentParser()
  subparsers = parser.add_subparsers(help='types of A')
  
  parser.add_argument(&quot;-t&quot;,
                      choices = [&quot;A&quot;, &quot;B&quot;],
                      dest = &quot;type&quot;,
                      required=True,
                      action='store',
                      help=&quot;Some help blah blah&quot;)
  
  cam_parser = subparsers.add_parser('a1', help='Default')
  cam_parser.set_defaults(which='a1')
  
  cam_parser = subparsers.add_parser('a2', help='parse this instead of default')
  cam_parser.set_defaults(which='a2')
  
  
  parser.add_argument(&quot;-v&quot;,
                      nargs = '+',
                      required=True,
                      dest = &quot;version&quot;,
                      type=int,
                      action='store',
                      help=&quot;some version help blah blah&quot;)   
  
  argument = parser.parse_args()
  
  print argument.type
  print argument.version
  </code></pre>