From 03a0a1c5992131249676dbb18f0d6e428857dadf Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 4 Sep 2014 17:58:28 +0200 Subject: [PATCH] commands: Handle ArgumentParser exit. --- qutebrowser/commands/argparser.py | 12 ++++++++++-- qutebrowser/commands/command.py | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qutebrowser/commands/argparser.py b/qutebrowser/commands/argparser.py index 69ef61920..2aa704e1a 100644 --- a/qutebrowser/commands/argparser.py +++ b/qutebrowser/commands/argparser.py @@ -31,6 +31,15 @@ class ArgumentParserError(Exception): """Exception raised when the ArgumentParser signals an error.""" +class ArgumentParserExit(Exception): + + """Exception raised when the argument parser exitted.""" + + def __init__(self, status, msg): + self.status = status + super().__init__(msg) + + class ArgumentParser(argparse.ArgumentParser): """Subclass ArgumentParser to be more suitable for runtime parsing.""" @@ -39,8 +48,7 @@ class ArgumentParser(argparse.ArgumentParser): super().__init__(add_help=False) def exit(self, status=0, msg=None): - raise AssertionError('exit called, this should never happen. ' - 'Status: {}, message: {}'.format(status, msg)) + raise ArgumentParserExit(status, msg) def error(self, msg): raise ArgumentParserError(msg[0].upper() + msg[1:]) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 72af36f37..58b3b9911 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -119,6 +119,10 @@ class Command: except argparser.ArgumentParserError as e: message.error('{}: {}'.format(self.name, e)) return + except argparser.ArgumentParserExit as e: + log.commands.debug("argparser exited with status {}: {}".format( + e.status, e)) + return for name, arg in vars(namespace).items(): if isinstance(arg, list):