forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexceptions.py
47 lines (34 loc) · 1.25 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
SoftLayer.CLI.exceptions
~~~~~~~~~~~~~~~~~~~~~~~~
Exceptions to be used in the CLI modules.
:license: MIT, see LICENSE for more details.
"""
# pylint: disable=keyword-arg-before-vararg
class CLIHalt(SystemExit):
"""Smoothly halt the execution of the command. No error."""
def __init__(self, code=0, *args):
super().__init__(*args)
self.code = code
def __str__(self):
message = getattr(self, 'message')
return f"<CLIHalt code={self.code} msg={message}>"
__repr__ = __str__
class CLIAbort(CLIHalt):
"""Halt the execution of the command. Gives an exit code of 2."""
def __init__(self, msg, *args):
super().__init__(code=2, *args)
self.message = msg
def __str__(self):
message = getattr(self, 'message')
return f"<CLIAbort code={self.code} msg={message}>"
__repr__ = __str__
class ArgumentError(CLIAbort):
"""Halt the execution of the command because of invalid arguments."""
def __init__(self, msg, *args):
super().__init__(msg, *args)
self.message = "Argument Error: %s" % msg
def __str__(self):
message = getattr(self, 'message')
return f"<ArgumentError code={self.code} msg={message}>"
__repr__ = __str__