From fb4e4856d1db4308fd6ebe4e869e9de06d3a0645 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 17 Aug 2009 19:13:09 +0000 Subject: [PATCH] Show an error instead of crashing when trying to use a command option without a required argument --- deluge/ui/console/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index 7c8acd046..68de4f53f 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -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__)