Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <QtCore/QJsonValue>
8#include <QtCore/QString>
9
10#include <exception>
11#include <optional>
12#include <utility>
13
14namespace Sonde::Cli {
15
18struct Exit : std::exception
19{
21 Exit(QString text, int exitStatus) : message(std::move(text)), status(exitStatus) { }
22
23 QString message;
24 int status;
25};
26
29[[noreturn]] void fail(const QString &message, int status = 3);
30
32[[noreturn]] void exitWith(int status);
33
35void write(const QString &text);
36
38void print(const QString &text);
39
41void printError(const QString &text);
42
44QString nativePath(const QString &path);
45
47QString pyStr(const QJsonValue &value);
48
51QString pyRepr(const QJsonValue &value);
52
54QString pyJson(const QJsonValue &value);
55
58std::optional<QJsonValue> parseJson(const QByteArray &data, QString *error);
59
60} // namespace Sonde::Cli
std::optional< QJsonValue > parseJson(const QByteArray &data, QString *error)
Any JSON value in data (an object, array, string, number, true, false or null), or nothing with error...
Definition common.cpp:195
QString pyRepr(const QJsonValue &value)
value as Python's repr() gives it for what json.load() returned.
Definition common.cpp:137
void print(const QString &text)
Writes text and a newline to stdout, as Python's print() does.
Definition common.cpp:115
void fail(const QString &message, int status)
Stops with "sonde: @p message" on stderr and exit status status (3, a configuration error,...
Definition common.cpp:100
void write(const QString &text)
Writes text to stdout, in UTF-8.
Definition common.cpp:110
QString nativePath(const QString &path)
path with the platform's separators, as Python's os.path functions give it.
Definition common.cpp:127
QString pyJson(const QJsonValue &value)
value as Python's json.dumps() gives it (ASCII only, ", " and ": ").
Definition common.cpp:166
void printError(const QString &text)
Writes text and a newline to stderr.
Definition common.cpp:120
void exitWith(int status)
Stops with exit status status, printing nothing more.
Definition common.cpp:105
QString pyStr(const QJsonValue &value)
value as Python's str() gives it for what json.load() returned.
Definition common.cpp:132
void status(const QJsonObject &config, const Project &project)
sonde status: whether the copy sonde started is running, its pid and endpoints.
Definition run.cpp:441
QString message
Printed after "sonde: " on stderr; nothing if empty.
Definition common.h:23
int status
The exit status.
Definition common.h:24
Exit(QString text, int exitStatus)
Stops with text (none if empty) and exitStatus.
Definition common.h:21