# HG changeset patch # User Jeff Hammel # Date 1397267440 25200 # Node ID 1bcf60bcc4557dcd0fab41bf9fec75f0bdd63605 # Parent 74f41d53b0576ed4bc181e2cf11419d9ca0fd603 update to argparse diff -r 74f41d53b057 -r 1bcf60bcc455 makeitso/python_package/{{package}}/{{main}}.py --- a/makeitso/python_package/{{package}}/{{main}}.py Fri Apr 11 17:06:22 2014 -0700 +++ b/makeitso/python_package/{{package}}/{{main}}.py Fri Apr 11 18:50:40 2014 -0700 @@ -6,30 +6,36 @@ """ # imports -import optparse +import argparse import os import subprocess import sys __all__ = ['main'] here = os.path.dirname(os.path.realpath(__file__)) +string = (str, unicode) -def add_options(parser): - """add options to the OptionParser instance""" +class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): + """description formatter for console script entry point""" + def format_description(self, description): + if description: + return description.strip() + '\n' + else: + return '' + + +class Parser(argparse.ArgumentParser): + """CLI option parser""" + def __init__(self): + argparse.ArgumentParser.__init__(self, description=__doc__) + def main(args=sys.argv[1:]): + """CLI""" # parse command line options - usage = '%prog [options] ...' - class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): - """description formatter for console script entry point""" - def format_description(self, description): - if description: - return description.strip() + '\n' - else: - return '' - parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) - options, args = parser.parse_args(args) + parser = Parser() + options = parser.parse_args(args) if __name__ == '__main__': main()