139
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 illustrate which options are parsed with argparse
|
|
5 """
|
|
6
|
|
7 import argparse
|
|
8 import sys
|
|
9
|
141
|
10 class Undefined(object):
|
|
11 """singleton"""
|
|
12
|
|
13 Undefined = Undefined()
|
|
14
|
|
15 class UndefinedArgumentParser(argparse.ArgumentParser):
|
|
16
|
142
|
17 def __init__(self, *args, **kwargs):
|
|
18
|
141
|
19 def add_argument(self, *args, **kwargs):
|
|
20 kwargs.setdefault('default', Undefined)
|
|
21 return argparse.ArgumentParser.add_argument
|
139
|
22
|
|
23 def main(args=sys.argv[1:]):
|
|
24
|
|
25 parser = UndefinedArgumentParser()
|
|
26 parser.add_argument('--foo', dest='foo',
|
|
27 help="foo")
|
|
28
|
|
29 if __name__ == '__main__':
|
|
30 main()
|