mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Commands - denotate
- Migrated handleDenotate to CmdDenotate.
This commit is contained in:
parent
f775341fd5
commit
d021bb8188
9 changed files with 192 additions and 107 deletions
|
@ -134,7 +134,6 @@ void Cmd::load ()
|
||||||
commands.push_back ("export.csv");
|
commands.push_back ("export.csv");
|
||||||
commands.push_back ("export.ical");
|
commands.push_back ("export.ical");
|
||||||
commands.push_back ("export.yaml");
|
commands.push_back ("export.yaml");
|
||||||
commands.push_back ("denotate");
|
|
||||||
commands.push_back ("calendar");
|
commands.push_back ("calendar");
|
||||||
commands.push_back ("colors");
|
commands.push_back ("colors");
|
||||||
commands.push_back ("config");
|
commands.push_back ("config");
|
||||||
|
@ -228,7 +227,6 @@ bool Cmd::isReadOnlyCommand ()
|
||||||
bool Cmd::isWriteCommand ()
|
bool Cmd::isWriteCommand ()
|
||||||
{
|
{
|
||||||
if (command == "merge" ||
|
if (command == "merge" ||
|
||||||
command == "denotate" ||
|
|
||||||
command == "delete" ||
|
command == "delete" ||
|
||||||
command == "done" ||
|
command == "done" ||
|
||||||
command == "duplicate" ||
|
command == "duplicate" ||
|
||||||
|
|
|
@ -252,7 +252,6 @@ int Context::dispatch (std::string &out)
|
||||||
else if (cmd.command == "summary") { rc = handleReportSummary (out); }
|
else if (cmd.command == "summary") { rc = handleReportSummary (out); }
|
||||||
else if (cmd.command == "calendar") { rc = handleReportCalendar (out); }
|
else if (cmd.command == "calendar") { rc = handleReportCalendar (out); }
|
||||||
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
|
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
|
||||||
else if (cmd.command == "denotate") { rc = handleDenotate (out); }
|
|
||||||
else if (cmd.command == "done") { rc = handleDone (out); }
|
else if (cmd.command == "done") { rc = handleDone (out); }
|
||||||
else if (cmd.command == "delete") { rc = handleDelete (out); }
|
else if (cmd.command == "delete") { rc = handleDelete (out); }
|
||||||
else if (cmd.command == "start") { rc = handleStart (out); }
|
else if (cmd.command == "start") { rc = handleStart (out); }
|
||||||
|
|
|
@ -1207,105 +1207,6 @@ int handleColor (std::string& outs)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleDenotate (std::string& outs)
|
|
||||||
{
|
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
if (!context.task.has ("description"))
|
|
||||||
throw std::string ("Description needed to delete an annotation.");
|
|
||||||
|
|
||||||
if (context.sequence.size () == 0)
|
|
||||||
throw std::string ("A task ID is needed to delete an annotation.");
|
|
||||||
|
|
||||||
bool sensitive = context.config.getBoolean ("search.case.sensitive");
|
|
||||||
|
|
||||||
std::stringstream out;
|
|
||||||
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
Filter filter;
|
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
|
|
||||||
context.filter.applySequence (tasks, context.sequence);
|
|
||||||
if (tasks.size () == 0)
|
|
||||||
{
|
|
||||||
std::cout << "No tasks specified.\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Permission permission;
|
|
||||||
if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
|
|
||||||
permission.bigSequence ();
|
|
||||||
|
|
||||||
foreach (task, tasks)
|
|
||||||
{
|
|
||||||
Task before (*task);
|
|
||||||
std::string desc = context.task.get ("description");
|
|
||||||
std::vector <Att> annotations;
|
|
||||||
task->getAnnotations (annotations);
|
|
||||||
|
|
||||||
if (annotations.size () == 0)
|
|
||||||
throw std::string ("The specified task has no annotations that can be deleted.");
|
|
||||||
|
|
||||||
std::vector <Att>::iterator i;
|
|
||||||
std::string anno;
|
|
||||||
bool match = false;;
|
|
||||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
|
||||||
{
|
|
||||||
anno = i->value ();
|
|
||||||
if (anno == desc)
|
|
||||||
{
|
|
||||||
match = true;
|
|
||||||
annotations.erase (i);
|
|
||||||
task->setAnnotations (annotations);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!match)
|
|
||||||
{
|
|
||||||
for (i = annotations.begin (); i != annotations.end (); ++i)
|
|
||||||
{
|
|
||||||
anno = i->value ();
|
|
||||||
std::string::size_type loc = find (anno, desc, sensitive);
|
|
||||||
|
|
||||||
if (loc != std::string::npos)
|
|
||||||
{
|
|
||||||
match = true;
|
|
||||||
annotations.erase (i);
|
|
||||||
task->setAnnotations (annotations);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskDiff (before, *task))
|
|
||||||
{
|
|
||||||
// Only allow valid tasks.
|
|
||||||
task->validate ();
|
|
||||||
|
|
||||||
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
|
|
||||||
{
|
|
||||||
context.tdb.update (*task);
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
|
||||||
out << "Found annotation '"
|
|
||||||
<< anno
|
|
||||||
<< "' and deleted it.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
out << "Did not find any matching annotation to be deleted for '"
|
|
||||||
<< desc
|
|
||||||
<< "'.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
outs = out.str ();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int deltaAppend (Task& task)
|
int deltaAppend (Task& task)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ set (commands_SRCS Command.cpp Command.h
|
||||||
CmdCommands.cpp CmdCommands.h
|
CmdCommands.cpp CmdCommands.h
|
||||||
CmdCount.cpp CmdCount.h
|
CmdCount.cpp CmdCount.h
|
||||||
CmdCustom.cpp CmdCustom.h
|
CmdCustom.cpp CmdCustom.h
|
||||||
|
CmdDenotate.cpp CmdDenotate.h
|
||||||
CmdDiagnostics.cpp CmdDiagnostics.h
|
CmdDiagnostics.cpp CmdDiagnostics.h
|
||||||
CmdEdit.cpp CmdEdit.h
|
CmdEdit.cpp CmdEdit.h
|
||||||
CmdExec.cpp CmdExec.h
|
CmdExec.cpp CmdExec.h
|
||||||
|
|
147
src/commands/CmdDenotate.cpp
Normal file
147
src/commands/CmdDenotate.cpp
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <Permission.h>
|
||||||
|
#include <text.h>
|
||||||
|
#include <main.h>
|
||||||
|
#include <CmdDenotate.h>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdDenotate::CmdDenotate ()
|
||||||
|
{
|
||||||
|
_keyword = "denotate";
|
||||||
|
_usage = "task denotate ID desc...";
|
||||||
|
_description = "Deletes an annotation from an existing task.";
|
||||||
|
_read_only = false;
|
||||||
|
_displays_id = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdDenotate::execute (const std::string&, std::string& output)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (!context.task.has ("description"))
|
||||||
|
throw std::string ("Description needed to delete an annotation.");
|
||||||
|
|
||||||
|
if (context.sequence.size () == 0)
|
||||||
|
throw std::string ("A task ID is needed to delete an annotation.");
|
||||||
|
|
||||||
|
bool sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
Filter filter;
|
||||||
|
context.tdb.loadPending (tasks, filter);
|
||||||
|
|
||||||
|
context.filter.applySequence (tasks, context.sequence);
|
||||||
|
if (tasks.size () == 0)
|
||||||
|
{
|
||||||
|
context.footnote ("No tasks specified.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Permission permission;
|
||||||
|
if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
|
||||||
|
permission.bigSequence ();
|
||||||
|
|
||||||
|
std::vector <Task>::iterator task;
|
||||||
|
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||||
|
{
|
||||||
|
Task before (*task);
|
||||||
|
std::string desc = context.task.get ("description");
|
||||||
|
std::vector <Att> annotations;
|
||||||
|
task->getAnnotations (annotations);
|
||||||
|
|
||||||
|
if (annotations.size () == 0)
|
||||||
|
throw std::string ("The specified task has no annotations that can be deleted.");
|
||||||
|
|
||||||
|
std::vector <Att>::iterator i;
|
||||||
|
std::string anno;
|
||||||
|
bool match = false;;
|
||||||
|
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||||
|
{
|
||||||
|
anno = i->value ();
|
||||||
|
if (anno == desc)
|
||||||
|
{
|
||||||
|
match = true;
|
||||||
|
annotations.erase (i);
|
||||||
|
task->setAnnotations (annotations);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!match)
|
||||||
|
{
|
||||||
|
for (i = annotations.begin (); i != annotations.end (); ++i)
|
||||||
|
{
|
||||||
|
anno = i->value ();
|
||||||
|
std::string::size_type loc = find (anno, desc, sensitive);
|
||||||
|
|
||||||
|
if (loc != std::string::npos)
|
||||||
|
{
|
||||||
|
match = true;
|
||||||
|
annotations.erase (i);
|
||||||
|
task->setAnnotations (annotations);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskDiff (before, *task))
|
||||||
|
{
|
||||||
|
// Only allow valid tasks.
|
||||||
|
task->validate ();
|
||||||
|
|
||||||
|
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
|
||||||
|
{
|
||||||
|
context.tdb.update (*task);
|
||||||
|
if (context.config.getBoolean ("echo.command"))
|
||||||
|
out << "Found annotation '"
|
||||||
|
<< anno
|
||||||
|
<< "' and deleted it.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
out << "Did not find any matching annotation to be deleted for '"
|
||||||
|
<< desc
|
||||||
|
<< "'.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
output = out.str ();
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
42
src/commands/CmdDenotate.h
Normal file
42
src/commands/CmdDenotate.h
Normal 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_CMDDENOTATE
|
||||||
|
#define INCLUDED_CMDDENOTATE
|
||||||
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <Command.h>
|
||||||
|
|
||||||
|
class CmdDenotate : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdDenotate ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -88,10 +88,6 @@ int CmdHelp::execute (const std::string&, std::string& output)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
row = view.addRow ();
|
|
||||||
view.set (row, 1, "task denotate ID desc...");
|
|
||||||
view.set (row, 2, "Deletes an annotation of an existing task.");
|
|
||||||
|
|
||||||
row = view.addRow ();
|
row = view.addRow ();
|
||||||
view.set (row, 1, "task ID [tags] [attrs] [desc...]");
|
view.set (row, 1, "task ID [tags] [attrs] [desc...]");
|
||||||
view.set (row, 2, "Modifies the existing task with provided arguments.");
|
view.set (row, 2, "Modifies the existing task with provided arguments.");
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <CmdCommands.h>
|
#include <CmdCommands.h>
|
||||||
#include <CmdCount.h>
|
#include <CmdCount.h>
|
||||||
#include <CmdCustom.h>
|
#include <CmdCustom.h>
|
||||||
|
#include <CmdDenotate.h>
|
||||||
#include <CmdDiagnostics.h>
|
#include <CmdDiagnostics.h>
|
||||||
#include <CmdEdit.h>
|
#include <CmdEdit.h>
|
||||||
#include <CmdExec.h>
|
#include <CmdExec.h>
|
||||||
|
@ -75,6 +76,7 @@ void Command::factory (std::map <std::string, Command*>& all)
|
||||||
c = new CmdCompletionTags (); all[c->keyword ()] = c;
|
c = new CmdCompletionTags (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
|
c = new CmdCompletionVersion (); all[c->keyword ()] = c;
|
||||||
c = new CmdCount (); all[c->keyword ()] = c;
|
c = new CmdCount (); all[c->keyword ()] = c;
|
||||||
|
c = new CmdDenotate (); all[c->keyword ()] = c;
|
||||||
c = new CmdDiagnostics (); all[c->keyword ()] = c;
|
c = new CmdDiagnostics (); all[c->keyword ()] = c;
|
||||||
c = new CmdEdit (); all[c->keyword ()] = c;
|
c = new CmdEdit (); all[c->keyword ()] = c;
|
||||||
c = new CmdExec (); all[c->keyword ()] = c;
|
c = new CmdExec (); all[c->keyword ()] = c;
|
||||||
|
|
|
@ -59,7 +59,6 @@ int handleDelete (std::string&);
|
||||||
int handleStart (std::string&);
|
int handleStart (std::string&);
|
||||||
int handleStop (std::string&);
|
int handleStop (std::string&);
|
||||||
int handleColor (std::string&);
|
int handleColor (std::string&);
|
||||||
int handleDenotate (std::string&);
|
|
||||||
int handleDuplicate (std::string&);
|
int handleDuplicate (std::string&);
|
||||||
void handleUndo ();
|
void handleUndo ();
|
||||||
void handleMerge (std::string&);
|
void handleMerge (std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue