Mercurial > python-cmd2
comparison cmd2.py @ 20:c8efa4369189
fixes to option parsing
author | catherine@cordelia |
---|---|
date | Thu, 15 May 2008 17:38:15 -0400 |
parents | 0eb8d4e18472 |
children | 82dde2f60e46 e72eb9137a87 |
comparison
equal
deleted
inserted
replaced
19:1899088dd95d | 20:c8efa4369189 |
---|---|
43 for opt in option_list: | 43 for opt in option_list: |
44 optionParser.add_option(opt) | 44 optionParser.add_option(opt) |
45 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) | 45 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) |
46 def newFunc(instance, arg): | 46 def newFunc(instance, arg): |
47 try: | 47 try: |
48 opts, arg = optionParser.parse_args(arg.split()) | 48 opts, arg = optionParser.parse_args(arg.split()) |
49 except optparse.OptionValueError, e: | 49 arg = ' '.join(arg) |
50 except (optparse.OptionValueError, optparse.BadOptionError, | |
51 optparse.OptionError, optparse.AmbiguousOptionError, | |
52 optparse.OptionConflictError), e: | |
50 print e | 53 print e |
51 optionParser.print_help() | 54 optionParser.print_help() |
52 return | 55 return |
53 result = func(instance, arg, opts) | 56 result = func(instance, arg, opts) |
54 return result | 57 return result |