mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Hooks
- Multiple hooks for the same event are now triggered, in the sequence they are found in .taskrc - Program hooks can now cause task to exit.
This commit is contained in:
parent
69cae7731f
commit
78063c4df7
3 changed files with 13 additions and 10 deletions
|
@ -490,10 +490,9 @@ bool API::callProgramHook (
|
|||
throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1);
|
||||
|
||||
// Call successful - get return values.
|
||||
// 0, nil -> success
|
||||
// 0, string -> warning
|
||||
// 1, string -> error
|
||||
if (!lua_isnumber (L, -2)) throw std::string ("Error: '") + function + "' did not return a success indicator";
|
||||
|
||||
// TODO This doesn't seem to know that 'nil' was returned instead of a string.
|
||||
// if (!lua_isstring (L, -1)) throw std::string ("Error: '") + function + "' did not return a message";
|
||||
|
||||
int rc = lua_tointeger (L, -2);
|
||||
|
@ -507,7 +506,7 @@ bool API::callProgramHook (
|
|||
else
|
||||
{
|
||||
if (message)
|
||||
throw std::string ("Error: ") + message;
|
||||
throw std::string (message);
|
||||
}
|
||||
|
||||
lua_pop (L, 1);
|
||||
|
|
|
@ -194,8 +194,7 @@ int Context::dispatch (std::string &out)
|
|||
|
||||
Timer t ("Context::dispatch");
|
||||
|
||||
if (! hooks.trigger ("pre-dispatch"))
|
||||
return rc;
|
||||
hooks.trigger ("pre-dispatch");
|
||||
|
||||
// TODO Just look at this thing. It cries out for a dispatch table.
|
||||
if (cmd.command == "projects") { rc = handleProjects (out); }
|
||||
|
|
|
@ -101,17 +101,22 @@ bool Hooks::trigger (const std::string& event)
|
|||
{
|
||||
if (it->event == event)
|
||||
{
|
||||
bool rc = true;
|
||||
std::string type;
|
||||
if (eventType (event, type))
|
||||
{
|
||||
// TODO Figure out where to get the calling-context info from.
|
||||
if (type == "program") return api.callProgramHook (it->file, it->function);
|
||||
else if (type == "list") return api.callListHook (it->file, it->function/*, tasks*/);
|
||||
else if (type == "task") return api.callTaskHook (it->file, it->function, 0);
|
||||
else if (type == "field") return api.callFieldHook (it->file, it->function, "field", "value");
|
||||
if (type == "program") rc = api.callProgramHook (it->file, it->function);
|
||||
else if (type == "list") rc = api.callListHook (it->file, it->function/*, tasks*/);
|
||||
else if (type == "task") rc = api.callTaskHook (it->file, it->function, 0);
|
||||
else if (type == "field") rc = api.callFieldHook (it->file, it->function, "field", "value");
|
||||
}
|
||||
else
|
||||
throw std::string ("Unrecognized hook event '") + event + "'";
|
||||
|
||||
// If any hook returns false, stop.
|
||||
if (!rc)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue