Feature #546
- Added feature #546, which is a 'count' command that counts tasks, and is intended to help scripts that manipulate task output. - Added unit tests. - Added man page description.
This commit is contained in:
@@ -2032,6 +2032,37 @@ int handleDuplicate (std::string& outs)
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleCount (std::string& outs)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (context.hooks.trigger ("pre-count-command"))
|
||||
{
|
||||
// Scan the pending tasks, applying any filter.
|
||||
std::vector <Task> tasks;
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
handleRecurrence ();
|
||||
context.tdb.load (tasks, context.filter);
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Find number of matching tasks. Skip recurring parent tasks.
|
||||
int count = 0;
|
||||
std::vector <Task>::iterator it;
|
||||
for (it = tasks.begin (); it != tasks.end (); ++it)
|
||||
if (it->getStatus () != Task::recurring)
|
||||
++count;
|
||||
|
||||
std::stringstream out;
|
||||
out << count << "\n";
|
||||
outs = out.str ();
|
||||
context.hooks.trigger ("post-count-command");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef FEATURE_SHELL
|
||||
void handleShell ()
|
||||
|
||||
Reference in New Issue
Block a user