Skip to content

Commit

Permalink
generic: scopy api add function for running a list of scripts
Browse files Browse the repository at this point in the history
command from cmd is :
 ./scopy -S={"script1","script2",...}
or
 ./scopy -S "script1" -S "script2"...

Signed-off-by: Ionut Muthi <[email protected]>
  • Loading branch information
IonutMuthi committed Jul 1, 2024
1 parent f80b560 commit 44d548c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/include/core/scopymainwindow_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions core/src/cmdlinehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions core/src/scopymainwindow_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit 44d548c

Please sign in to comment.