Dokit
Internal development documentation
Loading...
Searching...
No Matches
AbstractCommand Class Referenceabstract

The AbstractCommand class provides a consistent base for the classes that implement CLI commands. More...

Inheritance diagram for AbstractCommand:
[legend]
Collaboration diagram for AbstractCommand:
[legend]

Public Types

enum class  OutputFormat { Csv , Json , Text }
 Supported output formats. More...

Public Slots

virtual QStringList processOptions (const QCommandLineParser &parser)
 Processes the relevant options from the command line parser.
virtual bool start ()=0
 Begins the functionality of this command, and returns true if begun successfully, false otherwise.

Public Member Functions

 AbstractCommand (QObject *const parent=nullptr)
 Constructs a new command with parent.
virtual QStringList requiredOptions (const QCommandLineParser &parser) const
 Returns a list of CLI option names required by this command.
virtual QStringList supportedOptions (const QCommandLineParser &parser) const
 Returns a list of CLI option names supported by this command.
Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 QObject (QObject *parent)
virtual bool event (QEvent *e)
virtual bool eventFilter (QObject *watched, QEvent *event)
QString objectName () const const
void setObjectName (const QString &name)
bool isWidgetType () const const
bool isWindowType () const const
bool signalsBlocked () const const
bool blockSignals (bool block)
QThreadthread () const const
void moveToThread (QThread *targetThread)
int startTimer (int interval, Qt::TimerType timerType)
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
void killTimer (int id)
findChild (const QString &name, Qt::FindChildOptions options) const const
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
const QObjectListchildren () const const
void setParent (QObject *parent)
void installEventFilter (QObject *filterObj)
void removeEventFilter (QObject *obj)
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
bool disconnect (const QObject *receiver, const char *method) const const
void dumpObjectTree ()
void dumpObjectInfo ()
void dumpObjectTree () const const
void dumpObjectInfo () const const
bool setProperty (const char *name, const QVariant &value)
QVariant property (const char *name) const const
QList< QByteArraydynamicPropertyNames () const const
void destroyed (QObject *obj)
void objectNameChanged (const QString &objectName)
QObjectparent () const const
bool inherits (const char *className) const const
void deleteLater ()
 Q_DISABLE_COPY (Class)
 Q_DISABLE_MOVE (Class)
 Q_DISABLE_COPY_MOVE (Class)
qobject_cast (QObject *object)
qobject_cast (const QObject *object)
qFindChild (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 Q_CLASSINFO (Name, Value)
 Q_INTERFACES (...)
 Q_PROPERTY (...)
 Q_ENUMS (...)
 Q_FLAGS (...)
 Q_ENUM (...)
 Q_FLAG (...)
 Q_ENUM_NS (...)
 Q_FLAG_NS (...)
 Q_OBJECT Q_OBJECT
 Q_GADGET Q_GADGET
 Q_NAMESPACE Q_NAMESPACE
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 Q_SIGNALS Q_SIGNALS
 Q_SIGNAL Q_SIGNAL
 Q_SLOTS Q_SLOTS
 Q_SLOT Q_SLOT
 Q_EMIT Q_EMIT
 Q_INVOKABLE Q_INVOKABLE
 Q_REVISION Q_REVISION
 Q_SET_OBJECT_NAME (Object)
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT

Static Public Member Functions

static QString appendSiPrefix (const double value, int precision=6)
 Returns a human-readable version of value, with up-to precision decimal digits, and SI unit prefix when appropiate.
static QString escapeCsvField (const QString &field)
 Returns an RFC 4180 compliant version of field.
template<typename R, typename T = quint32>
static T parseNumber (const QString &value, const QString &unit, const T sensibleMinimum=0)
 Returns value as an integer multiple of the ratio R, as number of type T.
Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
bool disconnect (const QMetaObject::Connection &connection)
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)

Protected Slots

virtual void deviceDiscovered (const QBluetoothDeviceInfo &info)=0
 Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
virtual void deviceDiscoveryFinished ()=0
 Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.

Static Protected Member Functions

static Q_LOGGING_CATEGORY (lc, "dokit.cli.command", QtInfoMsg)
 Logging category for UI commands.

Protected Attributes

QString deviceToScanFor
 Device (if any) that were passed to processOptions().
PokitDiscoveryAgentdiscoveryAgent
 Agent for Pokit device discovery.
OutputFormat format { OutputFormat::Text }
 Selected output format.

Additional Inherited Members

Public Attributes inherited from QObject
typedef QObjectList
Protected Member Functions inherited from QObject
QObjectsender () const const
int senderSignalIndex () const const
int receivers (const char *signal) const const
bool isSignalConnected (const QMetaMethod &signal) const const
virtual void timerEvent (QTimerEvent *event)
virtual void childEvent (QChildEvent *event)
virtual void customEvent (QEvent *event)
virtual void connectNotify (const QMetaMethod &signal)
virtual void disconnectNotify (const QMetaMethod &signal)
Properties inherited from QObject
 objectName

Detailed Description

The AbstractCommand class provides a consistent base for the classes that implement CLI commands.

Definition at line 16 of file abstractcommand.h.

Member Enumeration Documentation

◆ OutputFormat

enum class AbstractCommand::OutputFormat
strong

Supported output formats.

Enumerator
Csv 

RFC 4180 compliant CSV text.

Json 

RFC 8259 compliant JSON text.

Text 

Plain unstructured text.

Definition at line 22 of file abstractcommand.h.

22 {
23 Csv, ///< RFC 4180 compliant CSV text.
24 Json, ///< RFC 8259 compliant JSON text.
25 Text, ///< Plain unstructured text.
26 };

Constructor & Destructor Documentation

◆ AbstractCommand()

AbstractCommand::AbstractCommand ( QObject *const parent = nullptr)
explicit

Constructs a new command with parent.

Definition at line 28 of file abstractcommand.cpp.

28 : QObject(parent),
29 discoveryAgent(new PokitDiscoveryAgent(this))
30{
36 #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
37 QOverload<PokitDiscoveryAgent::Error>::of(&PokitDiscoveryAgent::error),
38 #else
39 &PokitDiscoveryAgent::errorOccurred,
40 #endif
41 this, [](const PokitDiscoveryAgent::Error &error) {
42 qCWarning(lc).noquote() << tr("Bluetooth discovery error:") << error;
44 QCoreApplication::exit(EXIT_FAILURE);
45 });
46 });
47}
virtual void deviceDiscovered(const QBluetoothDeviceInfo &info)=0
Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
PokitDiscoveryAgent * discoveryAgent
Agent for Pokit device discovery.
virtual void deviceDiscoveryFinished()=0
Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.
void pokitDeviceDiscovered(const QBluetoothDeviceInfo &info)
This signal is emitted when the Pokit device described by info is discovered.
QBluetoothDeviceDiscoveryAgent::Error error() const const
void exit(int returnCode)
QCoreApplication * instance()
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)

References QObject::connect(), deviceDiscovered(), deviceDiscoveryFinished(), discoveryAgent, QBluetoothDeviceDiscoveryAgent::error(), QCoreApplication::exit(), QBluetoothDeviceDiscoveryAgent::finished(), QCoreApplication::instance(), QObject::parent(), PokitDiscoveryAgent::pokitDeviceDiscovered(), QObject::QObject(), QTimer::singleShot, and QObject::tr().

Referenced by DeviceCommand::DeviceCommand(), deviceDiscoveryFinished(), and ScanCommand::ScanCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ appendSiPrefix()

QString AbstractCommand::appendSiPrefix ( const double value,
int precision = 6 )
static

Returns a human-readable version of value, with up-to precision decimal digits, and SI unit prefix when appropiate.

Note
Only supports positive values. Tip: use appendSiPrefix(qAbs(...)) for now.

Definition at line 104 of file abstractcommand.cpp.

104 {
105 // Scale the number to an appropriate SI prefix.
106 QStringList siPrefixes{ u""_s, u"m"_s, u"μ"_s };
107 int index = 0;
108 if (value != 0.)
109 for (index=0; (index < siPrefixes.length()-1) && (qAbs(value) * qPow(1000.0, (double)index) < 1); ++index);
110 QString number = QString::number(value * qPow(1000.0, (double)index), 'f', precision);
111
112 // Trim trailing zeros, and decimal indicator if no decimals remain.
113 if (const DOKIT_STRING_INDEX_TYPE decimalPos = number.indexOf(u'.'); decimalPos > 0) {
114 DOKIT_STRING_INDEX_TYPE nonZeroPos;
115 for (nonZeroPos = number.length()-1; (nonZeroPos > decimalPos) && (number.at(nonZeroPos) == u'0'); --nonZeroPos);
116 number.truncate((nonZeroPos == decimalPos) ? nonZeroPos : nonZeroPos+1);
117 }
118 return QString(u"%1%2"_s).arg(number, siPrefixes.at(index));
119}
const T & at(int i) const const
int length() const const
const QChar at(int position) const const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
int length() const const
QString number(int n, int base)
void truncate(int position)
#define DOKIT_STRING_INDEX_TYPE
Internal macro for matching the index type used by QString methods.

References QString::arg(), QList::at(), QString::at(), DOKIT_STRING_INDEX_TYPE, QString::indexOf(), QList::length(), QString::length(), QString::number(), and QString::truncate().

Referenced by DsoCommand::processOptions(), and DsoCommand::serviceDetailsDiscovered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deviceDiscovered

virtual void AbstractCommand::deviceDiscovered ( const QBluetoothDeviceInfo & info)
protectedpure virtualslot

Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.

Derived classes must implement this slot to begin whatever actions are relevant when a Pokit device has been discovered. For example, the 'scan' command would simply output the info details, whereas most other commands would begin connecting if info is the device they're after.

Referenced by AbstractCommand().

Here is the caller graph for this function:

◆ deviceDiscoveryFinished

virtual void AbstractCommand::deviceDiscoveryFinished ( )
protectedpure virtualslot

Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.

Derived classes must implement this slot to perform whatever actions are appropriate when discovery is finished. For example, the 'scan' command would simply exit, whereas most other commands would verify that an appropriate device was found.

References AbstractCommand().

Referenced by AbstractCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escapeCsvField()

QString AbstractCommand::escapeCsvField ( const QString & field)
static

Returns an RFC 4180 compliant version of field.

That is, if field contains any of the the below four characters, than any double quotes are escaped (by addition double-quotes), and the string itself surrounded in double-quotes. Otherwise, field is returned verbatim.

Some examples:

QCOMPARE(escapeCsvField("abc"), "abc"); // Returned unchanged.
QCOMPARE(escapeCsvField("a,c"), R"("a,c")"); // Wrapped in double-quotes.
QCOMPARE(escapeCsvField(R"(a"c)"), R("("a""c")"); // Existing double-quotes doubled, then wrapped.
static QString escapeCsvField(const QString &field)
Returns an RFC 4180 compliant version of field.

Definition at line 133 of file abstractcommand.cpp.

134{
135 if (field.contains(','_L1) || field.contains('\r'_L1) || field.contains('"'_L1) || field.contains('\n'_L1)) {
136 return uR"("%1")"_s.arg(QString(field).replace('"'_L1, uR"("")"_s));
137 } else return field;
138}
bool contains(QChar ch, Qt::CaseSensitivity cs) const const

References QString::contains().

Referenced by ScanCommand::deviceDiscovered(), StatusCommand::outputDeviceStatus(), MeterCommand::outputReading(), and InfoCommand::serviceDetailsDiscovered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseNumber()

template<typename R, typename T>
T AbstractCommand::parseNumber ( const QString & value,
const QString & unit,
const T sensibleMinimum = 0 )
static

Returns value as an integer multiple of the ratio R, as number of type T.

The string value may end with the optional unit, such as V or s, which may also be preceded with a SI unit prefix such as m for milli. If value contains no SI unit prefix, then the result will be multiplied by 1,000 enough times to be greater than sensibleMinimum. This allows for convenient use like:

const quint32 timeout = parseNumber<std::milli>(parser.value("window"), 's', (quint32)500'000);
static T parseNumber(const QString &value, const QString &unit, const T sensibleMinimum=0)
Returns value as an integer multiple of the ratio R, as number of type T.

So that an unqualified period like "300" will be assumed to be 300 milliseconds, and not 300 microseconds, while a period like "1000" will be assume to be 1 second.

If conversion fails for any reason, quiet-NaN (if supported by T) or 0 is returned.

Definition at line 174 of file abstractcommand.cpp.

175{
176 static const QMap<QChar, Ratio> unitPrefixScaleMap {
177 { 'E'_L1, makeRatio<std::exa>() },
178 { 'P'_L1, makeRatio<std::peta>() },
179 { 'T'_L1, makeRatio<std::tera>() },
180 { 'G'_L1, makeRatio<std::giga>() },
181 { 'M'_L1, makeRatio<std::mega>() },
182 { 'K'_L1, makeRatio<std::kilo>() }, // Not official SI unit prefix, but commonly used.
183 { 'k'_L1, makeRatio<std::kilo>() },
184 { 'h'_L1, makeRatio<std::hecto>() },
185 { 'd'_L1, makeRatio<std::deci>() },
186 { 'c'_L1, makeRatio<std::centi>() },
187 { 'm'_L1, makeRatio<std::milli>() },
188 { 'u'_L1, makeRatio<std::micro>() }, // Not official SI unit prefix, but commonly used.
189 { QChar(0x00B5), makeRatio<std::micro>() }, // Unicode micro symbol (µ).
190 { QChar(0x03BC), makeRatio<std::micro>() }, // Unicode lower mu (μ).
191 { 'n'_L1, makeRatio<std::nano>() },
192 { 'p'_L1, makeRatio<std::pico>() },
193 { 'f'_L1, makeRatio<std::femto>() },
194 { 'a'_L1, makeRatio<std::atto>() },
195 };
196
197 // Remove the optional (whole) unit suffix.
198 Ratio ratio;
199 QString number = value.trimmed();
200 if ((!unit.isEmpty()) && (number.endsWith(unit, Qt::CaseInsensitive))) {
201 number.chop(unit.length());
202 ratio = makeRatio<std::ratio<1>>();
203 }
204
205 // Parse, and remove, the optional SI unit prefix.
206 if (!number.isEmpty()) {
207 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
208 const QChar siPrefix = number.back(); // QString::back() introduced in Qt 5.10.
209 #else
210 const QChar siPrefix = number.at(number.size() - 1);
211 #endif
212 const auto iter = unitPrefixScaleMap.constFind(siPrefix);
213 if (iter != unitPrefixScaleMap.constEnd()) {
214 Q_ASSERT(iter->isValid());
215 ratio = *iter;
216 number.chop(1);
217 }
218 }
219
220 // Parse the number as an (unsigned) integer.
221 QLocale locale; bool ok;
222 if (const qulonglong integer = locale.toULongLong(number, &ok); (ok)) {
223 if (integer == 0) {
224 return static_cast<T>(integer); // Otherwise the next for loop would be be infinite.
225 }
226 #define DOKIT_RESULT(var) (static_cast<T>(var) * ratio.num * R::den / ratio.den / R::num)
227 if (!ratio.isValid()) {
228 for (ratio = makeRatio<R>(); DOKIT_RESULT(integer) < sensibleMinimum; ratio.num *= 1000);
229 }
230 return DOKIT_RESULT(integer);
231 #undef DOKIT_RESULT
232 }
233
234 // Parse the number as a (double) floating point number, and check that it is positive.
235 if (const double dbl = locale.toDouble(number, &ok); (ok) && (dbl > 0.0)) {
236 if (dbl == 0.) {
237 return static_cast<T>(dbl); // Otherwise the next for loop would be be infinite.
238 }
239 #define DOKIT_RESULT(var) (var * ratio.num * R::den / ratio.den / R::num)
240 if (!ratio.isValid()) {
241 for (ratio = makeRatio<R>(); DOKIT_RESULT(dbl) < sensibleMinimum; ratio.num *= 1000);
242 }
243 return (std::is_integral_v<T>) ? static_cast<T>(std::llround(DOKIT_RESULT(dbl))) : DOKIT_RESULT(dbl);
244 #undef DOKIT_RESULT
245 }
246
247 // Failed to parse as either integer, or float.
248 return (std::numeric_limits<T>::has_quiet_NaN) ? std::numeric_limits<T>::quiet_NaN() : 0;
249}
double toDouble(const QString &s, bool *ok) const const
qulonglong toULongLong(const QString &s, bool *ok) const const
QMap::const_iterator constEnd() const const
QMap::const_iterator constFind(const Key &key) const const
QChar back() const const
void chop(int n)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
int size() const const
QString trimmed() const const
CaseInsensitive
std::intmax_t num
Numerator.
bool isValid() const
Returns true if both num and den are non-zero.

References QString::at(), QString::back(), Qt::CaseInsensitive, QString::chop(), QMap::constEnd(), QMap::constFind(), QString::endsWith(), QString::isEmpty(), Ratio::isValid(), QString::length(), Ratio::num, QString::size(), QLocale::toDouble(), QLocale::toULongLong(), and QString::trimmed().

Referenced by processOptions(), DsoCommand::processOptions(), LoggerStartCommand::processOptions(), and MeterCommand::processOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processOptions

QStringList AbstractCommand::processOptions ( const QCommandLineParser & parser)
virtualslot

Processes the relevant options from the command line parser.

On success, returns an empty QStringList, otherwise returns a list of CLI errors that the caller should report appropriately before exiting.

This base implementations performs some common checks, such as ensuring that required options are present. Derived classes should override this function to perform further processing, typically invoking this base implementation as a first step, such as:

QStringList CustomCommand::processOptions(const QCommandLineParser &parser)
{
if (!errors.isEmpty()) {
return errors;
}
// Do further procession of options.
return errors;
}
virtual QStringList processOptions(const QCommandLineParser &parser)
Processes the relevant options from the command line parser.
bool isEmpty() const const

Definition at line 297 of file abstractcommand.cpp.

298{
299 // Report any supplied options that are not supported by this command.
300 const QStringList suppliedOptionNames = parser.optionNames();
301 const QStringList supportedOptionNames = supportedOptions(parser);
302 for (const QString &option: suppliedOptionNames) {
303 if (!supportedOptionNames.contains(option)) {
304 qCInfo(lc).noquote() << tr("Ignoring option: %1").arg(option);
305 }
306 }
307 QStringList errors;
308
309 // Parse the device (name/addr/uuid) option.
310 if (parser.isSet(u"device"_s)) {
311 deviceToScanFor = parser.value(u"device"_s);
312 }
313
314 // Parse the output format options (if supported, and supplied).
315 if ((supportedOptionNames.contains(u"output"_s)) && // Derived classes may have removed.
316 (parser.isSet(u"output"_s)))
317 {
318 const QString output = parser.value(u"output"_s).toLower();
319 if (output == u"csv"_s) {
321 } else if (output == u"json"_s) {
323 } else if (output == u"text"_s) {
325 } else {
326 errors.append(tr("Unknown output format: %1").arg(output));
327 }
328 }
329
330 // Parse the device scan timeout option.
331 if (parser.isSet(u"timeout"_s)) {
332 const quint32 timeout = parseNumber<std::milli>(parser.value(u"timeout"_s), u"s"_s, 500);
333 if (timeout == 0) {
334 errors.append(tr("Invalid timeout: %1").arg(parser.value(u"timeout"_s)));
335 } else if (discoveryAgent->lowEnergyDiscoveryTimeout() == -1) {
336 qCWarning(lc).noquote() << tr("Platform does not support Bluetooth scan timeout");
337 } else {
338 discoveryAgent->setLowEnergyDiscoveryTimeout(timeout);
339 qCDebug(lc).noquote() << tr("Set scan timeout to %1").arg(
340 discoveryAgent->lowEnergyDiscoveryTimeout());
341 }
342 }
343
344 // Return errors for any required options that are absent.
345 const QStringList requiredOptionNames = this->requiredOptions(parser);
346 for (const QString &option: requiredOptionNames) {
347 if (!parser.isSet(option)) {
348 errors.append(tr("Missing required option: %1").arg(option));
349 }
350 }
351 return errors;
352}
QString deviceToScanFor
Device (if any) that were passed to processOptions().
virtual QStringList supportedOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names supported by this command.
OutputFormat format
Selected output format.
@ Text
Plain unstructured text.
@ Csv
RFC 4180 compliant CSV text.
@ Json
RFC 8259 compliant JSON text.
virtual QStringList requiredOptions(const QCommandLineParser &parser) const
Returns a list of CLI option names required by this command.
bool isSet(const QString &name) const const
QStringList optionNames() const const
QString value(const QString &optionName) const const
void append(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString toLower() const const
bool contains(const QString &str, Qt::CaseSensitivity cs) const const

References QList::append(), QString::arg(), QStringList::contains(), Csv, deviceToScanFor, discoveryAgent, format, QCommandLineParser::isSet(), Json, QCommandLineParser::optionNames(), parseNumber(), requiredOptions(), supportedOptions(), Text, QString::toLower(), QObject::tr(), and QCommandLineParser::value().

Referenced by CalibrateCommand::processOptions(), DsoCommand::processOptions(), FlashLedCommand::processOptions(), InfoCommand::processOptions(), LoggerStartCommand::processOptions(), MeterCommand::processOptions(), ScanCommand::processOptions(), SetNameCommand::processOptions(), SetTorchCommand::processOptions(), and StatusCommand::processOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requiredOptions()

QStringList AbstractCommand::requiredOptions ( const QCommandLineParser & parser) const
virtual

Returns a list of CLI option names required by this command.

The main console appication may use this list to output an error (and exit) if any of the returned names are not found in the parsed CLI options.

The (already parsed) parser may be used adjust the returned required options depending on the value of other options. For example, the logger command only requires the --mode option if the --command option is start.

This base implementation simply returns an empty list. Derived classes should override this function to include any required options.

Reimplemented in CalibrateCommand, DsoCommand, FlashLedCommand, InfoCommand, LoggerStartCommand, MeterCommand, ScanCommand, SetNameCommand, SetTorchCommand, and StatusCommand.

Definition at line 61 of file abstractcommand.cpp.

62{
63 Q_UNUSED(parser)
64 return QStringList();
65}

Referenced by processOptions(), CalibrateCommand::requiredOptions(), DsoCommand::requiredOptions(), FlashLedCommand::requiredOptions(), InfoCommand::requiredOptions(), LoggerStartCommand::requiredOptions(), MeterCommand::requiredOptions(), ScanCommand::requiredOptions(), SetNameCommand::requiredOptions(), SetTorchCommand::requiredOptions(), StatusCommand::requiredOptions(), and supportedOptions().

Here is the caller graph for this function:

◆ supportedOptions()

QStringList AbstractCommand::supportedOptions ( const QCommandLineParser & parser) const
virtual

Returns a list of CLI option names supported by this command.

The main console appication may use this list to output a warning for any parsed CLI options not included in the returned list.

The (already parsed) parser may be used adjust the returned supported options depending on the value of other options. For example, the logger command only supported the --timestamp option if the --command option is start.

This base implementation simply returns requiredOptions(). Derived classes should override this function to include optional options, such as:

QStringList Derived::supportedOptions(const QCommandLineParser &parser) const
{
list.sort();
list.removeDuplicates(); // Optional, recommended.
return list;
}
int removeDuplicates()
void sort(Qt::CaseSensitivity cs)

Reimplemented in CalibrateCommand, DsoCommand, FlashLedCommand, InfoCommand, LoggerStartCommand, MeterCommand, ScanCommand, SetNameCommand, SetTorchCommand, and StatusCommand.

Definition at line 88 of file abstractcommand.cpp.

89{
90 return requiredOptions(parser) + QStringList{
91 u"debug"_s,
92 u"device"_s, u"d"_s,
93 u"output"_s,
94 u"timeout"_s,
95 };
96}

References requiredOptions().

Referenced by processOptions(), CalibrateCommand::supportedOptions(), DsoCommand::supportedOptions(), FlashLedCommand::supportedOptions(), InfoCommand::supportedOptions(), LoggerStartCommand::supportedOptions(), MeterCommand::supportedOptions(), ScanCommand::supportedOptions(), SetNameCommand::supportedOptions(), SetTorchCommand::supportedOptions(), and StatusCommand::supportedOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ deviceToScanFor

QString AbstractCommand::deviceToScanFor
protected

◆ discoveryAgent

PokitDiscoveryAgent* AbstractCommand::discoveryAgent
protected

◆ format


The documentation for this class was generated from the following files: