diff --git a/core/include/core/scopymainwindow_api.h b/core/include/core/scopymainwindow_api.h index d36dfad696..927759d26f 100644 --- a/core/include/core/scopymainwindow_api.h +++ b/core/include/core/scopymainwindow_api.h @@ -22,6 +22,7 @@ class SCOPY_CORE_EXPORT ScopyMainWindow_API : public ApiObject Q_INVOKABLE void switchTool(QString devID, QString toolName); Q_INVOKABLE void switchTool(QString toolName); Q_INVOKABLE void runScript(QString scriptPath, bool exitApp = true); + Q_INVOKABLE void runScriptList(QStringList scriptPathList, bool exitApp = true); private: static bool sortByUUID(const QString &k1, const QString &k2); diff --git a/core/src/cmdlinehandler.cpp b/core/src/cmdlinehandler.cpp index 46060e40d0..66f0fd7388 100644 --- a/core/src/cmdlinehandler.cpp +++ b/core/src/cmdlinehandler.cpp @@ -34,6 +34,13 @@ int CmdLineHandler::handle(QCommandLineParser &parser, ScopyMainWindow_API &scop QMetaObject::invokeMethod(&scopyApi, "runScript", Qt::QueuedConnection, Q_ARG(QString, scriptPath), Q_ARG(bool, exitApp)); } + + QStringList scriptListPath = parser.values("script-list"); + if(!scriptListPath.isEmpty()) { + bool exitApp = !keepRunning; + QMetaObject::invokeMethod(&scopyApi, "runScriptList", Qt::QueuedConnection, Q_ARG(QStringList, scriptListPath), + Q_ARG(bool, exitApp)); + } return EXIT_SUCCESS; } diff --git a/core/src/scopymainwindow_api.cpp b/core/src/scopymainwindow_api.cpp index d74f56961f..f678288395 100644 --- a/core/src/scopymainwindow_api.cpp +++ b/core/src/scopymainwindow_api.cpp @@ -167,6 +167,18 @@ void ScopyMainWindow_API::runScript(QString scriptPath, bool exitApp) qApp->exit(ret); } +void ScopyMainWindow_API::runScriptList(QStringList scriptPathList, bool exitApp) +{ + foreach (QString scriptPath, scriptPathList) { + runScript(scriptPath, false); + } + + if(exitApp) { + int ret = EXIT_SUCCESS; + qApp->exit(ret); + } +} + const QString ScopyMainWindow_API::getScriptContent(QFile *file) { QTextStream stream(file); diff --git a/main.cpp b/main.cpp index e7d2d7fecc..130d8ece49 100644 --- a/main.cpp +++ b/main.cpp @@ -88,6 +88,7 @@ int main(int argc, char *argv[]) parser.addVersionOption(); parser.addOptions({ {{"s", "script"}, "Run given script.", "script"}, + {{"S", "script-list"}, "Run given script list.", "script-list"}, {{"r", "keep-running"}, "Keep the application session after running a certain script."}, {{"a", "accept-license"}, "Accept the license in advance."}, {{"l", "logfile"}, "Saves all the logging messages into a file.", "filename"},