<commit_before>#include <QCoreApplication>
#include <QStringList>
#include <QLocalSocket>
#include <QTcpSocket>
#include <QScopedPointer>
#include <QUrl>

#include "qjsonrpcservice.h"

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    QStringList args = app.arguments();
    QString appName = args.takeFirst();
    bool notification = args.contains("-n");
    if (notification)
        args.removeAll("-n");

    if (args.size() < 3) {
        qDebug("usage: %s [-n] <service> <method> <arguments>", appName.toLocal8Bit().data());
        return -1;
    }

    // try to process socket
    QIODevice *device = 0;
    QScopedPointer<QIODevice> devicePtr(device);
    QString service = args.takeFirst();
    QUrl serviceUrl = QUrl::fromUserInput(service);
    QHostAddress serviceAddress(serviceUrl.host());
    if (serviceAddress.isNull()) {
        QLocalSocket *localSocket = new QLocalSocket;
        device = localSocket;
        localSocket->connectToServer(service);
        if (!localSocket->waitForConnected(5000)) {
            qDebug("could not connect to service: %s", service.toLocal8Bit().data());
            return -1;
        }
    } else {
        QTcpSocket *tcpSocket = new QTcpSocket;
        device = tcpSocket;
        int servicePort = serviceUrl.port() ? serviceUrl.port() : 5555;
        tcpSocket->connectToHost(serviceAddress, servicePort);
        if (!tcpSocket->waitForConnected(5000)) {
            qDebug("could not connect to host at %s:%d", serviceUrl.host().toLocal8Bit().data(),
                   servicePort);
            return -1;
        }
    }

    QJsonRpcSocket socket(device);
    QString method = args.takeFirst();
    QVariantList arguments;
    foreach (QString arg, args)
        arguments.append(arg);
    QJsonRpcMessage request = QJsonRpcMessage::createRequest(method, arguments);
    QJsonRpcMessage response = socket.sendMessageBlocking(request, 5000);
    if (response.type() == QJsonRpcMessage::Error) {
        qDebug("error(%d): %s", response.errorCode(), response.errorMessage().toLocal8Bit().data());
        return -1;
    }

    qDebug() << response.result();
}<commit_msg>actually send notification if its requested, allow for no arguments<commit_after>#include <QCoreApplication>
#include <QStringList>
#include <QLocalSocket>
#include <QTcpSocket>
#include <QScopedPointer>
#include <QUrl>

#include "qjsonrpcservice.h"

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    QStringList args = app.arguments();
    QString appName = args.takeFirst();
    bool notification = args.contains("-n");
    if (notification)
        args.removeAll("-n");

    if (args.size() < 2) {
        qDebug("usage: %s [-n] <service> <method> <arguments>", appName.toLocal8Bit().data());
        return -1;
    }

    // try to process socket
    QIODevice *device = 0;
    QScopedPointer<QIODevice> devicePtr(device);
    QString service = args.takeFirst();
    QUrl serviceUrl = QUrl::fromUserInput(service);
    QHostAddress serviceAddress(serviceUrl.host());
    if (serviceAddress.isNull()) {
        QLocalSocket *localSocket = new QLocalSocket;
        device = localSocket;
        localSocket->connectToServer(service);
        if (!localSocket->waitForConnected(5000)) {
            qDebug("could not connect to service: %s", service.toLocal8Bit().data());
            return -1;
        }
    } else {
        QTcpSocket *tcpSocket = new QTcpSocket;
        device = tcpSocket;
        int servicePort = serviceUrl.port() ? serviceUrl.port() : 5555;
        tcpSocket->connectToHost(serviceAddress, servicePort);
        if (!tcpSocket->waitForConnected(5000)) {
            qDebug("could not connect to host at %s:%d", serviceUrl.host().toLocal8Bit().data(),
                   servicePort);
            return -1;
        }
    }

    QJsonRpcSocket socket(device);
    QString method = args.takeFirst();
    QVariantList arguments;
    foreach (QString arg, args)
        arguments.append(arg);

    QJsonRpcMessage request = notification ? QJsonRpcMessage::createNotification(method, arguments) :
                                             QJsonRpcMessage::createRequest(method, arguments);
    QJsonRpcMessage response = socket.sendMessageBlocking(request, 5000);
    if (response.type() == QJsonRpcMessage::Error) {
        qDebug("error(%d): %s", response.errorCode(), response.errorMessage().toLocal8Bit().data());
        return -1;
    }

    qDebug() << response.result();
}
{'fraction_non_alphanumeric': 0.1317311971517579, 'fraction_numerical': 0.011570983533600357, 'mean_word_length': 3.060523938572719, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2745169', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1306, 'n_words': 294}