# HG changeset patch # User Jeff Hammel # Date 1393900412 28800 # Node ID 643c1f11ad9b337c14829c352a1f05a76290054a # Parent ee1c34d2f1c48022949776e7e845fed473bf23a4 CLI diff -r ee1c34d2f1c4 -r 643c1f11ad9b abbrev/main.py --- a/abbrev/main.py Sun Mar 02 19:01:54 2014 -0800 +++ b/abbrev/main.py Mon Mar 03 18:33:32 2014 -0800 @@ -5,7 +5,7 @@ abbreviate lists of words to e.g. single-letter switches """ -import optparse +import argparse import os import subprocess import sys @@ -31,22 +31,18 @@ self.lookup[abbrev] = word -def add_options(parser): - """add options to the OptionParser instance""" - def main(args=sys.argv[1:]): # 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 = argparse.ArgumentParser() + parser.add_argument('words', nargs='+', + help="words") + parser.add_argumnet('-m', '--max', dest='max', + type=int, default=1 + help="maximum number of letters to use") + options = parser.parse_args(args) + + abbrev = Abbrev if __name__ == '__main__': main()