Mercurial > hg > abbrev
changeset 1:643c1f11ad9b
CLI
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 03 Mar 2014 18:33:32 -0800 |
parents | ee1c34d2f1c4 |
children | aa57b8f607bd |
files | abbrev/main.py |
diffstat | 1 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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()