mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Hooks
- Implemented ::onModify.
This commit is contained in:
parent
0bb3be73da
commit
dee6f3a713
1 changed files with 24 additions and 8 deletions
|
@ -174,7 +174,7 @@ void Hooks::onAdd (Task& after)
|
|||
if (status == 0)
|
||||
{
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
context.header (*line);
|
||||
context.footnote (*line);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -206,19 +206,35 @@ void Hooks::onModify (const Task& before, Task& after)
|
|||
std::vector <std::string>::iterator i;
|
||||
for (i = _scripts.begin (); i != _scripts.end (); ++i)
|
||||
{
|
||||
if (i->substr (0, 9) == "on-modify")
|
||||
if (i->find ("/on-modify") != std::string::npos)
|
||||
{
|
||||
File script (*i);
|
||||
if (script.executable ())
|
||||
{
|
||||
// TODO Call all modify hook scripts.
|
||||
std::string afterJSON = after.composeJSON ();
|
||||
std::string input = before.composeJSON ()
|
||||
+ "\n"
|
||||
+ afterJSON;
|
||||
std::string output;
|
||||
int status = execute (*i, input, output);
|
||||
|
||||
// TODO On zero status:
|
||||
// - first line is modified JSON
|
||||
// - remaining lines --> context.footnote
|
||||
std::vector <std::string> lines;
|
||||
split (lines, output, '\n');
|
||||
std::vector <std::string>::iterator line;
|
||||
|
||||
// TODO On non-zero status:
|
||||
// - all stdout --> context.error
|
||||
if (status == 0)
|
||||
{
|
||||
after = Task (afterJSON);
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
context.footnote (*line);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
context.error (*line);
|
||||
|
||||
throw 0; // This is how hooks silently terminate processing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue