Command - count

- Migrated handleCount to CmdCount.
This commit is contained in:
Paul Beckingham 2011-05-28 16:05:07 -04:00
parent 27d6e7cc81
commit a7bc09d487
9 changed files with 114 additions and 35 deletions

View file

@ -142,7 +142,6 @@ void Cmd::load ()
commands.push_back ("burndown.daily");
commands.push_back ("burndown.weekly");
commands.push_back ("burndown.monthly");
commands.push_back ("count");
commands.push_back ("add");
commands.push_back ("append");
commands.push_back ("annotate");
@ -234,7 +233,6 @@ bool Cmd::isReadOnlyCommand ()
command == "burndown.daily" ||
command == "burndown.weekly" ||
command == "burndown.monthly" ||
command == "count" ||
command == "calendar" ||
command == "colors" ||
command == "config" ||

View file

@ -280,7 +280,6 @@ int Context::dispatch (std::string &out)
handleMerge (out); }
else if (cmd.command == "push") { handlePush (out); }
else if (cmd.command == "pull") { handlePull (out); }
else if (cmd.command == "count") { rc = handleCount (out); }
else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); }
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }
else if (cmd.command == "_query") { rc = handleQuery (out); }

View file

@ -1457,33 +1457,6 @@ int handleDuplicate (std::string& outs)
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleCount (std::string& outs)
{
int rc = 0;
// 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 ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleColor (std::string& outs)
{

View file

@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR}
set (commands_SRCS Command.cpp Command.h
CmdCommands.cpp CmdCommands.h
CmdCount.cpp CmdCount.h
CmdCustom.cpp CmdCustom.h
CmdDiagnostics.cpp CmdDiagnostics.h
CmdEdit.cpp CmdEdit.h

69
src/commands/CmdCount.cpp Normal file
View file

@ -0,0 +1,69 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <Context.h>
#include <main.h>
#include <CmdCount.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdCount::CmdCount ()
{
_keyword = "count";
_usage = "task count [<filter>]";
_description = "Shows only the number of matching tasks.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdCount::execute (const std::string& command_line, std::string& output)
{
// 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";
output = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdCount.h Normal file
View file

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_CMDCOUNT
#define INCLUDED_CMDCOUNT
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdCount : public Command
{
public:
CmdCount ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -232,10 +232,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
view.set (row, 2, "Displays all possible colors, a named sample, or a "
"legend containing all currently defined colors.");
row = view.addRow ();
view.set (row, 1, "task count [filter]");
view.set (row, 2, "Shows only the number of matching tasks.");
row = view.addRow ();
view.set (row, 1, "task config [name [value | '']]");
view.set (row, 2, "Add, modify and remove settings in the task configuration.");

View file

@ -29,6 +29,7 @@
#include <vector>
#include <Command.h>
#include <CmdCommands.h>
#include <CmdCount.h>
#include <CmdCustom.h>
#include <CmdDiagnostics.h>
#include <CmdEdit.h>
@ -58,6 +59,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdCompletionIds (); all[c->keyword ()] = c;
c = new CmdCompletionTags (); all[c->keyword ()] = c;
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
c = new CmdCount (); all[c->keyword ()] = c;
c = new CmdDiagnostics (); all[c->keyword ()] = c;
c = new CmdEdit (); all[c->keyword ()] = c;
c = new CmdExec (); all[c->keyword ()] = c;

View file

@ -68,7 +68,6 @@ int handleColor (std::string&);
int handleAnnotate (std::string&);
int handleDenotate (std::string&);
int handleDuplicate (std::string&);
int handleCount (std::string&);
void handleUndo ();
void handleMerge (std::string&);
void handlePush (std::string&);