Show an error instead of crashing when trying to use a command option without a required argument

This commit is contained in:
Andrew Resch 2009-08-17 19:13:09 +00:00
parent 2b31544754
commit fb4e4856d1

View file

@ -86,7 +86,7 @@ class OptionParser(optparse.OptionParser):
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
"""
raise
raise Exception(msg)
class BaseCommand(object):
@ -266,7 +266,12 @@ class ConsoleUI(component.Component):
parser._print_help(f)
parser.print_help = print_help
options, args = parser.parse_args(args)
try:
options, args = parser.parse_args(args)
except Exception, e:
self.write("{!error!}Error parsing options: %s" % e)
return
if not getattr(options, '_exit', False):
try:
ret = self._commands[cmd].handle(*args, **options.__dict__)