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(+) 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 From ab52aa233c0ec920dd95a23ac782525283422c85 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 26 Dec 2015 19:34:59 +0100 Subject: add the new option to the output --- akonadish/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akonadish/main.cpp b/akonadish/main.cpp index 6e7aa9e..1e3f2f5 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) (argc == 2 && qstrcmp(argv[1], "-") == 0); const bool fromScript = !startRepl && QFile::exists(argv[1]); - //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener; + //qDebug() << "state at startup is" << interactive << startRepl << startJsonListener << fromScript; QCoreApplication app(argc, argv); app.setApplicationName(argv[0]); -- cgit v1.2.3 From 9ac72f34268e5ca929f100acf9b00d62f7c49366 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 26 Dec 2015 19:35:08 +0100 Subject: ignore lines beginning with # as comments --- akonadish/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/akonadish/main.cpp b/akonadish/main.cpp index 1e3f2f5..fe8494b 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp @@ -73,6 +73,10 @@ int main(int argc, char *argv[]) QString line = f.readLine(); while (!line.isEmpty()) { + if (line.startsWith('#')) { + line = f.readLine(); + continue; + } SyntaxTree::self()->run(SyntaxTree::tokenize(line)); line = f.readLine(); } -- cgit v1.2.3 From 08bdecf2d3c938032312f6ede3662157f83013eb Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 26 Dec 2015 19:36:16 +0100 Subject: trim lines, ignore empty ones --- akonadish/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/akonadish/main.cpp b/akonadish/main.cpp index fe8494b..45bd5ea 100644 --- a/akonadish/main.cpp +++ b/akonadish/main.cpp @@ -71,14 +71,14 @@ int main(int argc, char *argv[]) return 1; } - QString line = f.readLine(); + QString line = f.readLine().trimmed(); while (!line.isEmpty()) { - if (line.startsWith('#')) { - line = f.readLine(); + if (line.isEmpty() || line.startsWith('#')) { + line = f.readLine().trimmed(); continue; } SyntaxTree::self()->run(SyntaxTree::tokenize(line)); - line = f.readLine(); + line = f.readLine().trimmed(); } exit(0); } else if (!interactive) { -- cgit v1.2.3 From 43dfb87b20b6dc7cccf72cf9adb55608e184eb76 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 26 Dec 2015 19:52:46 +0100 Subject: update --- akonadish/TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/akonadish/TODO b/akonadish/TODO index 469dbf2..93c4ff1 100644 --- a/akonadish/TODO +++ b/akonadish/TODO @@ -3,6 +3,8 @@ * improve modify/remove/create to autocomplete resource names * provide a setting to turn on/off user interaction during commands (e.g. deletion confirmations) * add a "ask the user a question" helper in State + * confirm deletions in remove +* handle env vars and similar for scripting purposes * key/value syntax objects * json objects! (set json on; ...) * make the shell generic and have it load a plugin matching the name of argv[0] for syntax -- cgit v1.2.3