def __init__(self, arguments={}):
super(_store_container_command, self).__init__(arguments)
self.arguments['container'] =\
- ValueArgument('Set container to operate on (not permanent)', '--container')
+ ValueArgument('Set container to work with (temporary)',
+ '--container')
self.container = None
self.path = None
except AssertionError as err:
raiseCLIError(err)
+ generic_details = ['Choose one of the following options:',
+ ' 1. Set store.container variable (permanent)',
+ ' /config set store.container <container>',
+ ' 2. --container=<container> (temporary, overrides 1)',
+ ' 3. Use <container>:<path> (temporary, overrides all)']
cont, sep, path = container_with_path.partition(':')
if sep:
if not cont:
- raiseCLIError(None, 'Container is missing\n', importance=1,
- details=['Choose one of the following options:',
- ' 1. Set store.container variable (permanent)',
- ' /config set store.container <container>',
- ' 2. --container=<container> (temporary, overrides 1)',
- ' 3. Use <container>:<path> (temporary, overides all)'])
+ raiseCLIError(CLISyntaxError('Container is missing\n',
+ details=generic_details))
alt_cont = self.get_argument('container')
if alt_cont and cont != alt_cont:
- raiseCLIError(None,
+ raiseCLIError(CLISyntaxError(
'Conflict: 2 containers (%s, %s)' % (cont, alt_cont),
- importance=1)
+ details=generic_details))
self.container = cont
if not path:
- raiseCLIError(None,
+ raiseCLIError(CLISyntaxError(
'Path is missing for object in container %s' % cont,
- importance=1,
- details='Usage: <container>:<object path>')
+ details=generic_details))
self.path = path
else:
alt_cont = self.get_argument('container') or self.client.container
else:
self.container = cont
raiseCLIError(CLISyntaxError(
- 'Syntax error: container and path are both required',
- importance=1,
- details='Usage: <container>:<object path>'))
+ 'Both container and path are required',
+ details=generic_details))
def main(self, container_with_path=None, path_is_optional=True):
super(_store_container_command, self).main()
class CLIError(Exception):
+
def __init__(self, message, details=[], importance=0):
"""
@message is the main message of the Error
"""
message += '' if message and message[-1] == '\n' else '\n'
super(CLIError, self).__init__(message)
- self.details = details if isinstance(details, list)\
+ self.details = list(details) if isinstance(details, list)\
else [] if details is None else ['%s' % details]
try:
self.importance = int(importance)
:raises CLIError: it is the purpose of this method
"""
from traceback import format_stack
+
stack = ['%s' % type(err)] if err else ['<kamaki.cli.errors.CLIError>']
stack += format_stack()
try:
details = ['%s' % details] if not isinstance(details, list)\
else list(details)
+ details += getattr(err, 'details', [])
if err:
origerr = '%s' % err
if origerr not in details + [message]:
details.append(origerr)
- try:
- details.append(err.details)
- except AttributeError:
- pass
message += '' if message and message[-1] == '\n' else '\n'
if status:
except ValueError:
raise CLIError(message, details, importance)
importance = status // 100
+ importance = getattr(err, 'importance', importance)
raise CLIError(message, details, importance)