Mercurial > hg > configuration
comparison example/argparse_undefined.py @ 141:c6aea14a3e2b
wip
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 01 Dec 2014 18:05:50 -0800 |
parents | 30abbd61ea5e |
children | efd2d3330296 |
comparison
equal
deleted
inserted
replaced
140:372315b3bb8e | 141:c6aea14a3e2b |
---|---|
5 """ | 5 """ |
6 | 6 |
7 import argparse | 7 import argparse |
8 import sys | 8 import sys |
9 | 9 |
10 class UndefinedArgumentParser(argparse.ArgumentParser) | 10 class Undefined(object): |
11 """singleton""" | |
12 | |
13 Undefined = Undefined() | |
14 | |
15 class UndefinedArgumentParser(argparse.ArgumentParser): | |
16 | |
17 def add_argument(self, *args, **kwargs): | |
18 kwargs.setdefault('default', Undefined) | |
19 return argparse.ArgumentParser.add_argument | |
11 | 20 |
12 def main(args=sys.argv[1:]): | 21 def main(args=sys.argv[1:]): |
13 | 22 |
14 parser = UndefinedArgumentParser() | 23 parser = UndefinedArgumentParser() |
15 parser.add_argument('--foo', dest='foo', | 24 parser.add_argument('--foo', dest='foo', |