From 04d0c52a43d3a64044b307118d74b36681806c47 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Wed, 1 Apr 2015 11:44:37 +0200 Subject: [PATCH] Hooks: Implement "Hooks v2" API - All hook scripts now receive key:value pair command line arguments. - Add only the basics: api, args, command, rc, data. Possibly more to come. --- src/Hooks.cpp | 26 ++++++++++++++++++++++++++ src/Hooks.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index eaf171543..ca2eafd03 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -520,6 +520,30 @@ void Hooks::assertFeedback (const std::vector & input) const } } +//////////////////////////////////////////////////////////////////////////////// +std::vector & Hooks::buildHookScriptArgs (std::vector & args) +{ + Variant v; + + // Hooks API version. + args.push_back ("api:2"); + + // Command line Taskwarrior was called with. + context.dom.get ("context.args", v); + args.push_back ("args:" + std::string (v)); + + // Command to be executed. + args.push_back ("command:" + context.cli.getCommand ()); + + // rc file used after applying all overrides. + args.push_back ("rc:" + context.rc_file._data); + + // Directory containing *.data files. + args.push_back ("data:" + context.data_dir._data); + + return args; +} + //////////////////////////////////////////////////////////////////////////////// int Hooks::callHookScript ( const std::string& script, @@ -546,6 +570,8 @@ int Hooks::callHookScript ( std::vector args; int status; + buildHookScriptArgs (args); + // Measure time for each hook if running in debug if (_debug >= 2) { diff --git a/src/Hooks.h b/src/Hooks.h index 1bb33a2f7..0040303e6 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -57,6 +57,7 @@ private: void assertNTasks (const std::vector &, unsigned int) const; void assertSameTask (const std::vector &, const Task&) const; void assertFeedback (const std::vector &) const; + std::vector & buildHookScriptArgs (std::vector &); int callHookScript (const std::string&, const std::vector &, std::vector &); private: