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);
|
throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1);
|
||||||
|
|
||||||
// Call successful - get return values.
|
// 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";
|
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";
|
// if (!lua_isstring (L, -1)) throw std::string ("Error: '") + function + "' did not return a message";
|
||||||
|
|
||||||
int rc = lua_tointeger (L, -2);
|
int rc = lua_tointeger (L, -2);
|
||||||
|
@ -507,7 +506,7 @@ bool API::callProgramHook (
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (message)
|
if (message)
|
||||||
throw std::string ("Error: ") + message;
|
throw std::string (message);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop (L, 1);
|
lua_pop (L, 1);
|
||||||
|
|
|
@ -194,8 +194,7 @@ int Context::dispatch (std::string &out)
|
||||||
|
|
||||||
Timer t ("Context::dispatch");
|
Timer t ("Context::dispatch");
|
||||||
|
|
||||||
if (! hooks.trigger ("pre-dispatch"))
|
hooks.trigger ("pre-dispatch");
|
||||||
return rc;
|
|
||||||
|
|
||||||
// TODO Just look at this thing. It cries out for a dispatch table.
|
// TODO Just look at this thing. It cries out for a dispatch table.
|
||||||
if (cmd.command == "projects") { rc = handleProjects (out); }
|
if (cmd.command == "projects") { rc = handleProjects (out); }
|
||||||
|
|
|
@ -101,17 +101,22 @@ bool Hooks::trigger (const std::string& event)
|
||||||
{
|
{
|
||||||
if (it->event == event)
|
if (it->event == event)
|
||||||
{
|
{
|
||||||
|
bool rc = true;
|
||||||
std::string type;
|
std::string type;
|
||||||
if (eventType (event, type))
|
if (eventType (event, type))
|
||||||
{
|
{
|
||||||
// TODO Figure out where to get the calling-context info from.
|
// TODO Figure out where to get the calling-context info from.
|
||||||
if (type == "program") return api.callProgramHook (it->file, it->function);
|
if (type == "program") rc = api.callProgramHook (it->file, it->function);
|
||||||
else if (type == "list") return api.callListHook (it->file, it->function/*, tasks*/);
|
else if (type == "list") rc = api.callListHook (it->file, it->function/*, tasks*/);
|
||||||
else if (type == "task") return api.callTaskHook (it->file, it->function, 0);
|
else if (type == "task") rc = api.callTaskHook (it->file, it->function, 0);
|
||||||
else if (type == "field") return api.callFieldHook (it->file, it->function, "field", "value");
|
else if (type == "field") rc = api.callFieldHook (it->file, it->function, "field", "value");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw std::string ("Unrecognized hook event '") + event + "'";
|
throw std::string ("Unrecognized hook event '") + event + "'";
|
||||||
|
|
||||||
|
// If any hook returns false, stop.
|
||||||
|
if (!rc)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue