From dee6f3a7133fd10fde97d1a5ba20c8bad3aae1d6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 14 May 2014 00:11:13 -0400 Subject: [PATCH] Hooks - Implemented ::onModify. --- src/Hooks.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index aadf1e355..5bbb2309a 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -174,7 +174,7 @@ void Hooks::onAdd (Task& after) if (status == 0) { for (line = lines.begin (); line != lines.end (); ++line) - context.header (*line); + context.footnote (*line); } else { @@ -206,19 +206,35 @@ void Hooks::onModify (const Task& before, Task& after) std::vector ::iterator i; for (i = _scripts.begin (); i != _scripts.end (); ++i) { - if (i->substr (0, 9) == "on-modify") + if (i->find ("/on-modify") != std::string::npos) { File script (*i); if (script.executable ()) { - // TODO Call all modify hook scripts. + std::string afterJSON = after.composeJSON (); + std::string input = before.composeJSON () + + "\n" + + afterJSON; + std::string output; + int status = execute (*i, input, output); - // TODO On zero status: - // - first line is modified JSON - // - remaining lines --> context.footnote + std::vector lines; + split (lines, output, '\n'); + std::vector ::iterator line; - // TODO On non-zero status: - // - all stdout --> context.error + if (status == 0) + { + after = Task (afterJSON); + for (line = lines.begin (); line != lines.end (); ++line) + context.footnote (*line); + } + else + { + for (line = lines.begin (); line != lines.end (); ++line) + context.error (*line); + + throw 0; // This is how hooks silently terminate processing. + } } } }