If you have command line arguments that start with a dash but are not
options, you typically need to insert the pseudo-argument '--' to
indicate that everything after that should be considered an argument,
regardless of whether or not it contains a '-' prefix. See the
documentation on "Arguments containing '-'" for more details:
http://argparse.googlecode.com/svn/trunk/doc/parse_args.html#arguments-containing
Steve
--
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
Another option would be to use the .parse_known_args method, which
just collects the unknown arguments into a list:
http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#partial-parsing
I think you're right that there are troubles getting what you want
with subcommands::
>>> parser = argparse.ArgumentParser()
>>> parser.add_subparsers().add_parser('foo')
>>> parser.parse_known_args(['foo', 'bar'])
usage: foo [-h]
foo: error: unrecognized arguments: bar
That's because _SubParsersAction.__call__ always calls .parse_args()
because it can't tell whether it's being called within parse_args() or
parse_known_args(). Feel free to file a feature request to make
parse_known_args work with subparsers as well. A patch doing so would
be even better since I'm not currently sure how to implement this. ;-)