view example/argparse_undefined.py @ 142:efd2d3330296

wip
author Jeff Hammel <k0scist@gmail.com>
date Mon, 01 Dec 2014 18:08:58 -0800
parents c6aea14a3e2b
children 2825b0fdf80e
line wrap: on
line source

#!/usr/bin/env python

"""
illustrate which options are parsed with argparse
"""

import argparse
import sys

class Undefined(object):
    """singleton"""

Undefined = Undefined()

class UndefinedArgumentParser(argparse.ArgumentParser):

    def __init__(self, *args, **kwargs):

    def add_argument(self, *args, **kwargs):
        kwargs.setdefault('default', Undefined)
        return argparse.ArgumentParser.add_argument

def main(args=sys.argv[1:]):

    parser = UndefinedArgumentParser()
    parser.add_argument('--foo', dest='foo',
                        help="foo")

if __name__ == '__main__':
    main()