From 2f5435c50fab7ba29322be18b6008dcffbfd5197 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 13 May 2014 21:49:56 -0400 Subject: [PATCH] Hooks - Added ::onModify. - Stubbed out functionality in all three hook methods. --- src/Hooks.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/Hooks.h | 1 + 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index abde14f47..bf23ac8c8 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -67,8 +67,25 @@ void Hooks::onLaunch () { context.timer_hooks.start (); - // TODO Call all launch hook scripts. - // TODO Non-zero exit status terminates launch. + std::vector ::iterator i; + for (i = _scripts.begin (); i != _scripts.end (); ++i) + { + if (i->substr (0, 9) == "on-launch") + { + File script (*i); + if (script.executable ()) + { + // TODO Call all launch hook scripts. + + // TODO On zero status: + // - all stdout --> context.footnote + + // TODO On non-zero status: + // - all stdout --> context.error + // - throw std::string ("Hook termination"); + } + } + } context.timer_hooks.stop (); } @@ -85,7 +102,60 @@ void Hooks::onExit () { context.timer_hooks.start (); - // TODO Call all exit hook scripts. + std::vector ::iterator i; + for (i = _scripts.begin (); i != _scripts.end (); ++i) + { + if (i->substr (0, 7) == "on-exit") + { + File script (*i); + if (script.executable ()) + { + // TODO Call all exit hook scripts. + + // TODO On zero status: + // - all stdout --> context.footnote + + // TODO On non-zero status: + // - all stdout --> context.error + } + } + } + + context.timer_hooks.stop (); +} + +//////////////////////////////////////////////////////////////////////////////// +// Occurs when: A task is modified, before it is committed. +// Data fed to stdin: before JSON +// after JSON +// Exit code: 0: Success +// !0: Failure +// Output handled: 0: modified after JSON +// context.footnote () +// !0: context.error () +void Hooks::onModify (const Task& before, const Task& after) +{ + context.timer_hooks.start (); + + std::vector ::iterator i; + for (i = _scripts.begin (); i != _scripts.end (); ++i) + { + if (i->substr (0, 7) == "on-modify") + { + File script (*i); + if (script.executable ()) + { + // TODO Call all modify hook scripts. + + // TODO On zero status: + // - first line is modified JSON + // - remaining lines --> context.footnote + + // TODO On non-zero status: + // - all stdout --> context.error + } + } + } context.timer_hooks.stop (); } diff --git a/src/Hooks.h b/src/Hooks.h index a8c5cc764..f9d55948a 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -42,6 +42,7 @@ public: void onLaunch (); void onExit (); + void onModify (const Task&, const Task&); private: std::vector _scripts;