mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-02 05:30:23 +02:00
Enhancement - Hooks
- Implemented a master switch rc.hooks=off that can shut off all hooks. Seems like a good idea. - Added support for 'hooks' and 'hook.*' as valid configuration entries.
This commit is contained in:
parent
ea8b4beede
commit
d09a079199
3 changed files with 41 additions and 32 deletions
|
@ -119,6 +119,7 @@ std::string Config::defaults =
|
||||||
"complete.all.projects=no # Include old project names in 'projects' command\n" // TODO
|
"complete.all.projects=no # Include old project names in 'projects' command\n" // TODO
|
||||||
"complete.all.tags=no # Include old tag names in 'tags' command\n" // TODO
|
"complete.all.tags=no # Include old tag names in 'tags' command\n" // TODO
|
||||||
"debug=no # Display diagnostics\n"
|
"debug=no # Display diagnostics\n"
|
||||||
|
"hooks=off # Hook system master switch\n"
|
||||||
"fontunderline=yes # Uses underlines rather than -------\n"
|
"fontunderline=yes # Uses underlines rather than -------\n"
|
||||||
"shell.prompt=task> # Prompt used by the shell command\n" // TODO
|
"shell.prompt=task> # Prompt used by the shell command\n" // TODO
|
||||||
"\n"
|
"\n"
|
||||||
|
|
|
@ -89,46 +89,53 @@ void Hooks::initialize ()
|
||||||
api.initialize ();
|
api.initialize ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector <std::string> vars;
|
// Allow a master switch to turn the whole thing off.
|
||||||
context.config.all (vars);
|
bool big_red_switch = context.config.getBoolean ("hooks");
|
||||||
|
if (big_red_switch)
|
||||||
std::vector <std::string>::iterator it;
|
|
||||||
for (it = vars.begin (); it != vars.end (); ++it)
|
|
||||||
{
|
{
|
||||||
std::string type;
|
std::vector <std::string> vars;
|
||||||
std::string name;
|
context.config.all (vars);
|
||||||
std::string value;
|
|
||||||
|
|
||||||
// "<type>.<name>"
|
std::vector <std::string>::iterator it;
|
||||||
Nibbler n (*it);
|
for (it = vars.begin (); it != vars.end (); ++it)
|
||||||
if (n.getUntil ('.', type) &&
|
|
||||||
type == "hook" &&
|
|
||||||
n.skip ('.') &&
|
|
||||||
n.getUntilEOS (name))
|
|
||||||
{
|
{
|
||||||
std::string value = context.config.get (*it);
|
std::string type;
|
||||||
Nibbler n (value);
|
std::string name;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
// <path>:<function> [, ...]
|
// "<type>.<name>"
|
||||||
while (!n.depleted ())
|
Nibbler n (*it);
|
||||||
|
if (n.getUntil ('.', type) &&
|
||||||
|
type == "hook" &&
|
||||||
|
n.skip ('.') &&
|
||||||
|
n.getUntilEOS (name))
|
||||||
{
|
{
|
||||||
std::string file;
|
std::string value = context.config.get (*it);
|
||||||
std::string function;
|
Nibbler n (value);
|
||||||
if (n.getUntil (':', file) &&
|
|
||||||
n.skip (':') &&
|
|
||||||
n.getUntil (',', function))
|
|
||||||
{
|
|
||||||
context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function);
|
|
||||||
Hook h (name, Path::expand (file), function);
|
|
||||||
all.push_back (h);
|
|
||||||
|
|
||||||
(void) n.skip (',');
|
// <path>:<function> [, ...]
|
||||||
|
while (!n.depleted ())
|
||||||
|
{
|
||||||
|
std::string file;
|
||||||
|
std::string function;
|
||||||
|
if (n.getUntil (':', file) &&
|
||||||
|
n.skip (':') &&
|
||||||
|
n.getUntil (',', function))
|
||||||
|
{
|
||||||
|
context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function);
|
||||||
|
Hook h (name, Path::expand (file), function);
|
||||||
|
all.push_back (h);
|
||||||
|
|
||||||
|
(void) n.skip (',');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw std::string ("Malformed hook definition '") + *it + "'";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
throw std::string ("Malformed hook definition '") + *it + "'";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
context.debug ("Hooks::initialize - hook system shut off");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -671,7 +671,7 @@ int handleConfig (std::string &outs)
|
||||||
"displayweeknumber echo.command fontunderline locking monthsperline nag "
|
"displayweeknumber echo.command fontunderline locking monthsperline nag "
|
||||||
"next project shadow.command shadow.file shadow.notify weekstart editor "
|
"next project shadow.command shadow.file shadow.notify weekstart editor "
|
||||||
"import.synonym.id import.synonym.uuid complete.all.projects "
|
"import.synonym.id import.synonym.uuid complete.all.projects "
|
||||||
"complete.all.tags search.case.sensitive "
|
"complete.all.tags search.case.sensitive hooks "
|
||||||
#ifdef FEATURE_SHELL
|
#ifdef FEATURE_SHELL
|
||||||
"shell.prompt "
|
"shell.prompt "
|
||||||
#endif
|
#endif
|
||||||
|
@ -700,7 +700,8 @@ int handleConfig (std::string &outs)
|
||||||
i->substr (0, 10) != "color.tag." &&
|
i->substr (0, 10) != "color.tag." &&
|
||||||
i->substr (0, 8) != "holiday." &&
|
i->substr (0, 8) != "holiday." &&
|
||||||
i->substr (0, 7) != "report." &&
|
i->substr (0, 7) != "report." &&
|
||||||
i->substr (0, 6) != "alias.")
|
i->substr (0, 6) != "alias." &&
|
||||||
|
i->substr (0, 5) != "hook.")
|
||||||
{
|
{
|
||||||
unrecognized.push_back (*i);
|
unrecognized.push_back (*i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue