From 75a2fd102611a01dba3ab7b9a26a2e05908a3a4c Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 26 Dec 2015 19:30:31 +0100 Subject: make it possible to write akonadish scripts.. help --- akonadish/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'akonadish') diff --git a/akonadish/main.cpp b/akonadish/main.cpp index bd85fb4..6e7aa9e 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include "syntaxtree.h" @@ -42,6 +43,8 @@ int main(int argc, char *argv[]) //TODO: make a json command parse cause that would be awesomesauce const bool startJsonListener = !startRepl && (argc == 2 && qstrcmp(argv[1], "-") == 0); + const bool fromScript = !startRepl && QFile::exists(argv[1]); + //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener; QCoreApplication app(argc, argv); @@ -62,6 +65,18 @@ int main(int argc, char *argv[]) State::setHasEventLoop(true); return app.exec(); + } else if (fromScript) { + QFile f(argv[1]); + if (!f.open(QIODevice::ReadOnly)) { + return 1; + } + + QString line = f.readLine(); + while (!line.isEmpty()) { + SyntaxTree::self()->run(SyntaxTree::tokenize(line)); + line = f.readLine(); + } + exit(0); } else if (!interactive) { QTextStream inputStream(stdin); while (true) { -- cgit v1.2.3