title: Python argparse optional sub-arguments
body: <p>I'd like to have an argument to my program that has some required parameters along with some optional parameters. Something like this:</p>
  
  <pre><code>[--print text [color [size]]
  </code></pre>
  
  <p>so you could pass it any of these:</p>
  
  <pre><code>mycommand --print hello
  mycommand --print hello blue
  mycommand --print hello red 12
  </code></pre>
  
  <p>There could be multiple of these so it has to be a single add_argument. For example:</p>
  
  <pre><code>[--print text [color]] [--output filename [overwrite]]
  </code></pre>
  
  <p>I can achieve arguments that are close to what I want:</p>
  
  <pre><code>&gt;&gt;&gt; parser = argparse.ArgumentParser()
  &gt;&gt;&gt; act = parser.add_argument('--foo', nargs=3, metavar=('x','y','z'))
  &gt;&gt;&gt; act = parser.add_argument('--bar', nargs='?')
  &gt;&gt;&gt; act = parser.add_argument('--baz', nargs='*')
  &gt;&gt;&gt; parser.print_help()
  usage: [-h] [--foo x y z] [--bar [BAR]] [--baz [BAZ [BAZ ...]]]
  
  optional arguments:
    -h, --help            show this help message and exit
    --foo x y z
    --bar [BAR]
    --baz [BAZ [BAZ ...]]
  </code></pre>
  
  <p>but not quite. Is there any way to do this with argparse? I know I could make them all <code>nargs="*"</code> but then --help would not list the names of the optional arguments. If I pass <code>nargs="*"</code> and a tuple for metavar, argparse throws an exception.</p>