commands: Handle ArgumentParser exit.
This commit is contained in:
parent
57d51ad9bb
commit
03a0a1c599
@ -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:])
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user