From 0bb3be73daf39302835be096bd28a1f5524d59ff Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 14 May 2014 00:05:47 -0400 Subject: [PATCH] Hooks - Implemented ::onAdd. --- src/Hooks.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 1884e9100..aadf1e355 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -158,19 +158,31 @@ void Hooks::onAdd (Task& after) std::vector ::iterator i; for (i = _scripts.begin (); i != _scripts.end (); ++i) { - if (i->substr (0, 6) == "on-add") + if (i->find ("/on-add") != std::string::npos) { File script (*i); if (script.executable ()) { - // TODO Call all modify hook scripts. + std::string input = after.composeJSON (); + 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) + { + for (line = lines.begin (); line != lines.end (); ++line) + context.header (*line); + } + else + { + for (line = lines.begin (); line != lines.end (); ++line) + context.error (*line); + + throw 0; // This is how hooks silently terminate processing. + } } } }