in modular_cli/service/decorators.py [0:0]
def __call__(self, fn):
@wraps(fn)
def decorated(*args, **kwargs):
_FUNC_LOG = _LOG.getChild(fn.__name__) # todo remove ?
view_format = CLI_VIEW
table_format = kwargs.pop(TABLE_VIEW, False)
json_format = kwargs.pop(JSON_VIEW, False)
if table_format:
view_format = TABLE_VIEW
elif json_format:
view_format = JSON_VIEW
global VIEW_FORMAT # there is no global
VIEW_FORMAT = view_format
resp = fn(*args, **kwargs) # CommandResponse
if not isinstance(resp, CommandResponse):
warn_message = ['Response is broken and does not match '
'CommandResponse object']
# todo this looks like developer's error. Exception here
_FUNC_LOG.warning(warn_message)
resp = CommandResponse(message=resp, warnings=warn_message,
code=400)
func_result = ResponseFormatter(function_result=resp,
view_format=view_format)
response = self.stdout(func_result.prettify_response())
if not ResponseFormatter.is_response_success(resp):
sys.exit(1)
return response
return decorated