def get_logs_json_handlers()

in wadebug/cli.py [0:0]


def get_logs_json_handlers(send, opt_out, logs_folder):
    def prepare_logs():
        if send and opt_out:
            output = {"success": False}
            output["error_msg"] = (
                "Passing --send flag requires to send data to Facebook.\n"
                "It's incompatible with --do-not-send-usage. "
                "Please use only one of those flags."
            )
            click.echo(json.dumps(output))
            sys.exit(-1)

    def handle_outputs(log_files, output, _zipped_logs_file_name):
        # _zipped_logs_file_name is not used in this function
        # it is in the function signature to keep it consistent with
        # other handle_outputs functions
        output["log_files"] = log_files
        output["success"] = True
        return output

    def handle_exceptions(exp, output):
        output["error_msg"] = "wadebug could not retrieve logs:\n{}\n".format(exp)
        click.echo(json.dumps(output))
        sys.exit(-1)

    def handle_upload_results(output, zipped_logs_file_handle):
        if Config().development_mode:
            return

        if send:
            send_logs_result = cli_utils.send_logs_to_fb(
                zipped_logs_file_handle,
                success_callback=send_logs_result_json_success,
                failure_callback=send_result_json_failure,
            )
            output.update(send_logs_result)
        elif not opt_out:
            cli_utils.send_results_to_fb(
                output,
                success_callback=send_usage_result_json_success,
                failure_callback=send_result_json_failure,
            )
        click.echo(json.dumps(output))

    return prepare_logs, handle_outputs, handle_exceptions, handle_upload_results