title: Nested options with argparse
body: <p>I'd like to have my python script take variable number of arguments depending on a particular choice. For example:</p>
  
  <p><code>python run.py foo</code></p>
  
  <p><code>python run.py bar X Y</code></p>
  
  <p>where choosing the option <code>bar</code> requires two additional arguments, say integer inputs, but <code>foo</code> requires no additional arguments.</p>
  
  <pre><code>import argparse
  
  argparser = argparse.ArgumentParser()
  # Allow user to choose test to run
  argparser.add_argument("test", choices=['foo', 'bar'], help="You may choose foo or bar.")
  ...
  </code></pre>
  
  <p>But how can I specify additional arguments required by <code>bar</code>? P.S. I'm working with Python 2.7, so if a solution requires Python 3, it won't be much help in my case.</p>