def main() -> None: # pylint: disable=broad-except argv = sys.argv[1:] if argv: _exit( communication.const.COM_STATUS_INPUT_ERROR, status_msg="No arguments allowed", ) utils.subprocess_setup() logging.basicConfig() try: input_dto = dto.from_dict( communication.dto.InternalCommunicationRequestDto, json.load(sys.stdin), ) cli_env = get_cli_env(input_dto.options) lib = Library(cli_env, utils.get_middleware_factory()) if input_dto.cmd not in SUPPORTED_COMMANDS: _exit( communication.const.COM_STATUS_UNKNOWN_CMD, status_msg=f"Unknown command '{input_dto.cmd}'", ) for sub_cmd in input_dto.cmd.split("."): lib = getattr(lib, sub_cmd) output_data = lib(**input_dto.cmd_data) # type: ignore _exit( communication.const.COM_STATUS_SUCCESS, report_list=cli_env.report_processor.processed_items, data=( dto.to_dict(output_data) if isinstance(output_data, dto.DataTransferObject) else output_data ), ) except LibraryError as e: _exit( communication.const.COM_STATUS_ERROR, report_list=( cli_env.report_processor.processed_items + list(e.args) ), data=e.output, ) except json.JSONDecodeError as e: _exit( communication.const.COM_STATUS_INPUT_ERROR, status_msg=f"Unable to parse input data: {e.msg}", ) except DaciteError as e: _exit( communication.const.COM_STATUS_INPUT_ERROR, status_msg=str(e), ) except Exception as e: # TODO: maybe add traceback? _exit(communication.const.COM_STATUS_EXCEPTION, status_msg=str(e))
def main(): # pylint: disable=broad-except argv = sys.argv[1:] if argv: _exit("input_error", status_msg="No arguments allowed") utils.subprocess_setup() logging.basicConfig() try: input_data = json.load(sys.stdin) cli_env = get_cli_env(input_data.get("options", {})) lib = Library(cli_env, utils.get_middleware_factory()) cmd = input_data["cmd"] if cmd not in SUPPORTED_COMMANDS: _exit("unknown_cmd", status_msg=f"Unknown command '{cmd}'") for sub_cmd in cmd.split("."): lib = getattr(lib, sub_cmd) output_data = lib(**input_data["cmd_data"]) _exit( "success", report_list=export_reports( cli_env.report_processor.processed_items ), data=output_data, ) except LibraryError as e: _exit( "error", report_list=export_reports( cli_env.report_processor.processed_items + list(e.args) ), ) except json.JSONDecodeError as e: _exit("input_error", status_msg=f"Unable to parse input data: {e.msg}") except KeyError as e: _exit("input_error", status_msg=f"Missing key {e}") except Exception as e: # TODO: maybe add traceback? _exit("exception", status_msg=str(e))