- 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:
Paul Beckingham
2010-11-26 10:39:00 -05:00
parent 4c40784328
commit d7de67d242
10 changed files with 129 additions and 0 deletions

View File

@@ -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 ()