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):
|
143
|
18 argparse.ArgumentParser.__init__(self, *args, **kwargs)
|
144
|
19 self.__defaults = {}
|
142
|
20
|
141
|
21 def add_argument(self, *args, **kwargs):
|
144
|
22 default = kwargs.pop('default', self.argument_default)
|
141
|
23 return argparse.ArgumentParser.add_argument
|
139
|
24
|
|
25 def main(args=sys.argv[1:]):
|
|
26
|
|
27 parser = UndefinedArgumentParser()
|
|
28 parser.add_argument('--foo', dest='foo',
|
|
29 help="foo")
|
|
30
|
|
31 if __name__ == '__main__':
|
|
32 main()
|