Commands - _urgency

- Migrated _urgency to CmdUrgency.
This commit is contained in:
Paul Beckingham 2011-05-28 14:07:21 -04:00
parent 9af1c71daf
commit bd93126f4e
8 changed files with 124 additions and 39 deletions

View file

@ -134,7 +134,6 @@ void Cmd::load ()
commands.push_back ("_commands");
commands.push_back ("_ids");
commands.push_back ("_config");
commands.push_back ("_urgency");
commands.push_back ("_query");
commands.push_back ("_zshcommands");
commands.push_back ("_zshids");
@ -236,7 +235,6 @@ bool Cmd::isReadOnlyCommand ()
command == "_commands" ||
command == "_ids" ||
command == "_config" ||
command == "_urgency" ||
command == "_query" ||
command == "_zshcommands" ||
command == "_zshids" ||

View file

@ -289,7 +289,6 @@ int Context::dispatch (std::string &out)
else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); }
else if (cmd.command == "_ids") { rc = handleCompletionIDs (out); }
else if (cmd.command == "_config") { rc = handleCompletionConfig (out); }
else if (cmd.command == "_urgency") { rc = handleUrgency (out); }
else if (cmd.command == "_query") { rc = handleQuery (out); }
else if (cmd.command == "_zshcommands") { rc = handleZshCompletionCommands (out); }
else if (cmd.command == "_zshids") { rc = handleZshCompletionIDs (out); }

View file

@ -411,41 +411,6 @@ int handleCompletionConfig (std::string& outs)
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Temporary command to display urgency for a task.
int handleUrgency (std::string& outs)
{
// Get all the tasks.
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
context.tdb.loadPending (tasks, context.filter);
context.tdb.commit ();
context.tdb.unlock ();
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
if (tasks.size () == 0)
{
std::cout << "No tasks specified.\n";
return 1;
}
// Find the task(s).
std::stringstream out;
foreach (task, tasks)
{
out << "task "
<< task->id
<< " urgency "
<< task->urgency ()
<< "\n";
}
outs = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleQuery (std::string& outs)
{

View file

@ -17,6 +17,7 @@ set (commands_SRCS Command.cpp Command.h
CmdShow.cpp CmdShow.h
CmdTags.cpp CmdTags.h
CmdTip.cpp CmdTip.h
CmdUrgency.cpp CmdUrgency.h
CmdVersion.cpp CmdVersion.h)
add_library (commands STATIC ${commands_SRCS})

View file

@ -0,0 +1,79 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <stdlib.h>
#include <Context.h>
#include <main.h>
#include <CmdUrgency.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdUrgency::CmdUrgency ()
{
_keyword = "_urgency";
_usage = "task _urgency <IDs>";
_description = "Displays the urgency measure of a task.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdUrgency::execute (const std::string& command_line, std::string& output)
{
// Get all the tasks.
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
context.tdb.loadPending (tasks, context.filter);
context.tdb.commit ();
context.tdb.unlock ();
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
if (tasks.size () == 0)
{
context.footnote ("No tasks specified.");
return 1;
}
// Find the task(s).
std::stringstream out;
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
out << "task "
<< task->id
<< " urgency "
<< task->urgency ()
<< "\n";
output = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdUrgency.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_CMDURGENCY
#define INCLUDED_CMDURGENCY
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdUrgency : public Command
{
public:
CmdUrgency ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -39,6 +39,7 @@
#include <CmdShow.h>
#include <CmdTags.h>
#include <CmdTip.h>
#include <CmdUrgency.h>
#include <CmdVersion.h>
#include <Context.h>
@ -60,6 +61,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdShow (); all[c->keyword ()] = c;
c = new CmdTags (); all[c->keyword ()] = c;
c = new CmdTip (); all[c->keyword ()] = c;
c = new CmdUrgency (); all[c->keyword ()] = c;
c = new CmdVersion (); all[c->keyword ()] = c;
// Instantiate a command object for each custom report.

View file

@ -62,7 +62,6 @@ int handleCompletionTags (std::string&);
int handleCompletionCommands (std::string&);
int handleCompletionIDs (std::string&);
int handleCompletionConfig (std::string&);
int handleUrgency (std::string&);
int handleQuery (std::string&);
int handleZshCompletionCommands (std::string&);
int handleZshCompletionIDs (std::string&);