mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Commands
- Promoted filtering code to the Command base class. - Added filtering short-circuit.
This commit is contained in:
parent
db17536266
commit
7762ee2f9e
14 changed files with 79 additions and 173 deletions
|
@ -32,7 +32,6 @@
|
|||
#include <Context.h>
|
||||
#include <Date.h>
|
||||
#include <Duration.h>
|
||||
#include <Expression.h>
|
||||
#include <main.h>
|
||||
#include <CmdBurndown.h>
|
||||
|
||||
|
@ -991,15 +990,9 @@ int CmdBurndownMonthly::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Create a chart, scan the tasks, then render.
|
||||
Chart chart ('M');
|
||||
|
@ -1041,15 +1034,9 @@ int CmdBurndownWeekly::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Create a chart, scan the tasks, then render.
|
||||
Chart chart ('W');
|
||||
|
@ -1091,15 +1078,9 @@ int CmdBurndownDaily::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Create a chart, scan the tasks, then render.
|
||||
Chart chart ('D');
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <iomanip>
|
||||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <ViewText.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
|
@ -71,15 +70,9 @@ int CmdCalendar::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
Date today;
|
||||
bool getpendingdate = false;
|
||||
|
@ -195,6 +188,7 @@ int CmdCalendar::execute (std::string& output)
|
|||
{
|
||||
// Find the oldest pending due date.
|
||||
Date oldest (12,31,2037);
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
if (task->getStatus () == Task::pending)
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <ViewTask.h>
|
||||
#include <Expression.h>
|
||||
#include <text.h>
|
||||
#include <main.h>
|
||||
#include <CmdCustom.h>
|
||||
|
@ -92,15 +91,9 @@ int CmdCustom::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Sort the tasks.
|
||||
std::vector <int> sequence;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include <sstream>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <ViewText.h>
|
||||
#include <main.h>
|
||||
#include <text.h>
|
||||
|
@ -63,16 +62,11 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
|
@ -228,16 +222,11 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
|
@ -390,16 +379,11 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
|
@ -595,16 +579,11 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <main.h>
|
||||
#include <util.h>
|
||||
#include <CmdIDs.h>
|
||||
|
@ -56,18 +55,13 @@ int CmdIDs::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Find number of matching tasks.
|
||||
std::vector <int> ids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->id)
|
||||
ids.push_back (task->id);
|
||||
|
@ -96,17 +90,12 @@ int CmdCompletionIds::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::vector <int> ids;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->getStatus () != Task::deleted &&
|
||||
task->getStatus () != Task::completed)
|
||||
|
@ -142,17 +131,12 @@ int CmdZshCompletionIds::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->getStatus () != Task::deleted &&
|
||||
task->getStatus () != Task::completed)
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <Date.h>
|
||||
#include <Duration.h>
|
||||
#include <ViewText.h>
|
||||
|
@ -60,15 +59,9 @@ int CmdInfo::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Read the undo file.
|
||||
std::vector <std::string> undo;
|
||||
|
@ -81,6 +74,7 @@ int CmdInfo::execute (std::string& output)
|
|||
|
||||
// Find the task.
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
ViewText view;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <main.h>
|
||||
#include <CmdQuery.h>
|
||||
|
||||
|
@ -55,15 +54,9 @@ int CmdQuery::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
if (filtered.size () == 0)
|
||||
{
|
||||
|
@ -81,6 +74,7 @@ int CmdQuery::execute (std::string& output)
|
|||
if (json_array)
|
||||
output += "[\n";
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
if (task != filtered.begin ())
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <ViewText.h>
|
||||
#include <Duration.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <main.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
|
@ -84,15 +83,9 @@ int CmdStatistics::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
Date now;
|
||||
time_t earliest = time (NULL);
|
||||
|
@ -110,6 +103,7 @@ int CmdStatistics::execute (std::string& output)
|
|||
std::map <std::string, int> allTags;
|
||||
std::map <std::string, int> allProjects;
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
++totalT;
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <Context.h>
|
||||
#include <ViewText.h>
|
||||
#include <Duration.h>
|
||||
#include <Expression.h>
|
||||
#include <text.h>
|
||||
#include <main.h>
|
||||
#include <CmdSummary.h>
|
||||
|
@ -63,18 +62,13 @@ int CmdSummary::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Generate unique list of project names from all pending tasks.
|
||||
std::map <std::string, bool> allProjects;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
if (task->getStatus () == Task::pending)
|
||||
allProjects[task->get ("project")] = false;
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <ViewText.h>
|
||||
#include <CmdTags.h>
|
||||
#include <text.h>
|
||||
|
@ -63,19 +62,14 @@ int CmdTags::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Scan all the tasks for their project name, building a map using project
|
||||
// names as keys.
|
||||
std::map <std::string, int> unique;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
std::vector <std::string> tags;
|
||||
|
@ -154,19 +148,14 @@ int CmdCompletionTags::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Scan all the tasks for their tags, building a map using tag
|
||||
// names as keys.
|
||||
std::map <std::string, int> unique;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
std::vector <std::string> tags;
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <ViewText.h>
|
||||
#include <Date.h>
|
||||
#include <main.h>
|
||||
|
@ -59,15 +58,9 @@ int CmdTimesheet::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Just do this once.
|
||||
int width = context.getWidth ();
|
||||
|
@ -118,6 +111,7 @@ int CmdTimesheet::execute (std::string& output)
|
|||
completed.add (Column::factory ("string.right", "Due"));
|
||||
completed.add (Column::factory ("string", "Description"));
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
// If task completed within range.
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Expression.h>
|
||||
#include <main.h>
|
||||
#include <CmdUrgency.h>
|
||||
|
||||
|
@ -55,17 +54,10 @@ int CmdUrgency::execute (std::string& output)
|
|||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
// Filter.
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
// Apply filter.
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
filter (tasks, filtered);
|
||||
|
||||
// Filter sequence.
|
||||
if (filtered.size () == 0)
|
||||
{
|
||||
context.footnote ("No tasks specified.");
|
||||
|
@ -74,6 +66,7 @@ int CmdUrgency::execute (std::string& output)
|
|||
|
||||
// Find the task(s).
|
||||
std::stringstream out;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
out << "task "
|
||||
<< task->id
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <Expression.h>
|
||||
#include <Command.h>
|
||||
|
||||
#include <CmdAdd.h>
|
||||
#include <CmdAnnotate.h>
|
||||
#include <CmdAppend.h>
|
||||
|
@ -249,3 +251,20 @@ bool Command::displays_id () const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
||||
{
|
||||
Arguments f = context.args.extract_read_only_filter ();
|
||||
if (f.size ())
|
||||
{
|
||||
Expression e (f);
|
||||
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = input.begin (); task != input.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
output.push_back (*task);
|
||||
}
|
||||
else
|
||||
output = input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
#define L10N // Localization complete.
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Task.h>
|
||||
|
||||
class Command
|
||||
{
|
||||
|
@ -49,6 +51,8 @@ public:
|
|||
bool displays_id () const;
|
||||
virtual int execute (std::string&) = 0;
|
||||
|
||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||
|
||||
protected:
|
||||
std::string _keyword;
|
||||
std::string _usage;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue