Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
common.h File Reference

What the sonde command's parts share: stopping with a status, printing, and JSON values written as the Python sonde wrote them (design 0030). More...

#include <QtCore/QJsonValue>
#include <QtCore/QString>
#include <exception>
#include <optional>
#include <utility>

Go to the source code of this file.

Classes

struct  Sonde::Cli::Exit
 Thrown to stop the command: main() prints the message, if any, and exits with the status. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

void Sonde::Cli::fail (const QString &message, int status=3)
 Stops with "sonde: @p message" on stderr and exit status status (3, a configuration error, unless said otherwise).
void Sonde::Cli::exitWith (int status)
 Stops with exit status status, printing nothing more.
void Sonde::Cli::write (const QString &text)
 Writes text to stdout, in UTF-8.
void Sonde::Cli::print (const QString &text)
 Writes text and a newline to stdout, as Python's print() does.
void Sonde::Cli::printError (const QString &text)
 Writes text and a newline to stderr.
QString Sonde::Cli::nativePath (const QString &path)
 path with the platform's separators, as Python's os.path functions give it.
QString Sonde::Cli::pyStr (const QJsonValue &value)
 value as Python's str() gives it for what json.load() returned.
QString Sonde::Cli::pyRepr (const QJsonValue &value)
 value as Python's repr() gives it for what json.load() returned.
QString Sonde::Cli::pyJson (const QJsonValue &value)
 value as Python's json.dumps() gives it (ASCII only, ", " and ": ").
std::optional< QJsonValue > Sonde::Cli::parseJson (const QByteArray &data, QString *error)
 Any JSON value in data (an object, array, string, number, true, false or null), or nothing with error set.

Detailed Description

What the sonde command's parts share: stopping with a status, printing, and JSON values written as the Python sonde wrote them (design 0030).

Function Documentation

◆ pyRepr()

QString Sonde::Cli::pyRepr ( const QJsonValue & value)

value as Python's repr() gives it for what json.load() returned.

Objects come with their keys sorted, as a Sonde server writes them.