title: Argparse: How to accept any number of optional arguments (starting with `-` or `--`)
body: <p>I'm trying to create a command line tool (let's call it 'X') that wraps another tool (let's call it 'Y').</p>
  
  <p>I handle some cases specially, and add some options of myself, but I want to redirect whatever I don't want to handle to the tool Y.</p>
  
  <p>So far I managed to redirect the arguments that don't come with dashes, for example <code>X Y option1 option2 option3</code> will just call <code>Y option1 option2 option3</code>. I did this by adding a subparser <code>Y</code> and an argument <code>any</code> to it</p>
  
  <p>Here's the code (x.py):</p>
  
  <pre><code>main_parser = argparse.ArgumentParser()
  subparsers = main_parser.add_subparsers(dest="parser_name")
  
  y_subparser = subparsers.add_parser('y')
  y_options = y_subparser.add_argument('any', nargs='*')
  </code></pre>
  
  <p>Then in my handler code, i do this:</p>
  
  <pre><code>args = main_parser.parse_args()
  if args.parser_name == 'y':
      command_string = ' '.join(['y'] + sys.argv[2:])
      os.system(command_string)
  </code></pre>
  
  <p>When I call <code>python x.py y asdf zxcv qwer</code> it works.</p>
  
  <p>When I call <code>python x.py y asdf zxcv qwer -option</code> I get the error <code>x.py: error: unrecognized arguments: -option</code></p>
  
  <p>I realize that if stuff just gets too complicated with argparse i can always fall back to using <code>sys.argv</code>, but if you know this to be doable, please share.</p>
  
  <p>I've also been looking through the argparse code, which is a little dense, and where it seems that <code>ArgumentParser._parse_known_args</code> does everything (300 lines). But before I go deeper, I thought maybe someone knows how to do this - if not, i'll post my discoveries here if someone else has the same problem.</p>