mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Hooks
- Implemented ::execute to run a command, feed it input, read it's output and return the exit status.
This commit is contained in:
parent
68436d0d50
commit
d30fb54a62
2 changed files with 41 additions and 1 deletions
|
@ -24,10 +24,13 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream> // TODO Remove
|
||||
#include <cmake.h>
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <Context.h>
|
||||
#include <Hooks.h>
|
||||
#include <text.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
|
@ -61,7 +64,7 @@ void Hooks::initialize ()
|
|||
// Data fed to stdin: None
|
||||
// Exit code: 0: Success, proceed
|
||||
// !0: Failure, terminate
|
||||
// Output handled: 0: context.footnote ()
|
||||
// Output handled: 0: context.header ()
|
||||
// !0: context.error ()
|
||||
void Hooks::onLaunch ()
|
||||
{
|
||||
|
@ -196,3 +199,37 @@ void Hooks::onModify (const Task& before, Task& after)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Hooks::execute (
|
||||
const std::string& command,
|
||||
const std::string& input,
|
||||
std::string& output)
|
||||
{
|
||||
FILE* fp = popen (command.c_str (), "r+");
|
||||
if (fp)
|
||||
{
|
||||
// Write input to fp.
|
||||
if (input != "")
|
||||
{
|
||||
fputs (input.c_str (), fp);
|
||||
fflush (fp);
|
||||
}
|
||||
|
||||
// Read output from fp.
|
||||
output = "";
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
while (getline (&line, &len, fp) != -1)
|
||||
{
|
||||
output += line;
|
||||
free (line);
|
||||
line = NULL;
|
||||
}
|
||||
|
||||
fflush (fp);
|
||||
return pclose (fp);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
void onAdd (Task&);
|
||||
void onModify (const Task&, Task&);
|
||||
|
||||
private:
|
||||
int execute (const std::string&, const std::string&, std::string&);
|
||||
|
||||
private:
|
||||
std::vector <std::string> _scripts;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue