11
11
12
12
namespace Ripes {
13
13
14
- // An extended QVariant-to-string convertion method which handles a few special
15
- // cases.
14
+ /* *
15
+ * An extended QVariant-to-string convertion method which handles a special
16
+ * cases such as QVariantMap and QStringList.
17
+ *
18
+ * @param v The QVariant to convert to a string.
19
+ * @returns A string representation of the QVariant.
20
+ */
16
21
static QString qVariantToString (QVariant &v) {
17
22
QString def = v.toString ();
18
23
if (!def.isEmpty ())
@@ -34,6 +39,14 @@ static QString qVariantToString(QVariant &v) {
34
39
return def;
35
40
}
36
41
42
+ /* *
43
+ * Constructor for the CLIRunner class.
44
+ * Initializes the CLI runner for Ripes.
45
+ * It configures the environment based on the provided options and prepares the
46
+ * SystemIO streams for input and output redirection.
47
+ *
48
+ * @param options A struct containing the CLI options for Ripes.
49
+ */
37
50
CLIRunner::CLIRunner (const CLIModeOptions &options)
38
51
: QObject(), m_options(options) {
39
52
info (" Ripes CLI mode" , false , true );
@@ -46,9 +59,18 @@ CLIRunner::CLIRunner(const CLIModeOptions &options)
46
59
std::flush (std::cout);
47
60
});
48
61
49
- // TODO: how to handle system input?
62
+ // Handle systemIO input in stdin
63
+ SystemIO::setCLIInput ();
50
64
}
51
65
66
+ /* *
67
+ * Main execution method for the CLI runner.
68
+ * Runs the CLI process in three phases: process input, run model, and post-run.
69
+ * Checks after each phase that the execution was successful, and returns 1 if
70
+ * an error occurs during any phase.
71
+ *
72
+ * @return 0 on success, or 1 if an error occurs during any phase.
73
+ */
52
74
int CLIRunner::run () {
53
75
if (processInput ())
54
76
return 1 ;
@@ -62,6 +84,13 @@ int CLIRunner::run() {
62
84
return 0 ;
63
85
}
64
86
87
+ /* *
88
+ * Processes the input file based on the file source type in the provided CLI
89
+ * options. The method prepares the program for the execution by assembling,
90
+ * compiling, or loading the input file (based on the source type).
91
+ *
92
+ * @return 0 on success, or 1 if an error occurs during input file processing.
93
+ */
65
94
int CLIRunner::processInput () {
66
95
info (" Processing input file" , false , true );
67
96
@@ -157,11 +186,15 @@ int CLIRunner::processInput() {
157
186
return 0 ;
158
187
}
159
188
189
+ /* *
190
+ * Runs the processor model for the loaded program until the program is
191
+ * finished (so ProcessorHandler::runFinished signal is emitted)
192
+ *
193
+ * @return 0 on success, or 1 if an error occurs during model execution.
194
+ */
160
195
int CLIRunner::runModel () {
161
196
info (" Running model" , false , true );
162
197
163
- // Wait until receiving ProcessorHandler::runFinished signal
164
- // before proceeding.
165
198
QEventLoop loop;
166
199
QObject::connect (ProcessorHandler::get (), &ProcessorHandler::runFinished,
167
200
&loop, &QEventLoop::quit);
@@ -212,6 +245,13 @@ int CLIRunner::runModel() {
212
245
return 0 ;
213
246
}
214
247
248
+ /* *
249
+ * Handles post-execution tasks.
250
+ * Open output file (if specified) or defaults to stdout and prints telemetry
251
+ * data in either JSON or unstructured format.
252
+ *
253
+ * @return 0 on success, or 1 if an error occurs during post run tasks.
254
+ */
215
255
int CLIRunner::postRun () {
216
256
info (" Post-run" , false , true );
217
257
@@ -256,6 +296,17 @@ int CLIRunner::postRun() {
256
296
return 0 ;
257
297
}
258
298
299
+ /* *
300
+ * Outputs an informational message to the standard output.
301
+ * For formatting purposes the message can include a header or a specified
302
+ * prefix.
303
+ *
304
+ * @param msg The QString message to print.
305
+ * @param alwaysPrint If true, the message is printed regardless if the verbose
306
+ * option is disabled.
307
+ * @param header If true, the message is surrounded by a decorative header.
308
+ * @param prefix The prefix for the message, added only if "header" is false.
309
+ */
259
310
void CLIRunner::info (QString msg, bool alwaysPrint, bool header,
260
311
const QString &prefix) {
261
312
@@ -276,6 +327,11 @@ void CLIRunner::info(QString msg, bool alwaysPrint, bool header,
276
327
}
277
328
}
278
329
330
+ /* *
331
+ * Prints an error message to stdout with an "ERROR" prefix.
332
+ *
333
+ * @param msg The error message to print.
334
+ */
279
335
void CLIRunner::error (const QString &msg) { info (msg, true , false , " ERROR" ); }
280
336
281
337
} // namespace Ripes
0 commit comments