ThomasWaldmann / argparse

python argparse, pypi version (moved from google code)
Other
59 stars 18 forks source link

parser.parse_known_args() does not work with subparsers #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
parse_known_args raises an error with subparsers (without subparsers it 
seems okay).  Example script:

import argparse

p = argparse.ArgumentParser()
sub = p.add_subparsers(dest='command')
foo = sub.add_parser('foo')
foo.add_argument('--test')
bar = sub.add_parser('bar')

def parse(*args):
    args = list(args)
    try:
        result = p.parse_known_args(args)
        print args, '->', result
    except SystemExit, e:
        print args, '-exit->', e

parse('foo')
parse('foo', '--test', 'this')
parse('bar')
parse('foo', '--blah')

Original issue reported on code.google.com by ianbick...@gmail.com on 14 Jan 2010 at 11:29

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 15 Jan 2010 at 12:18