Command - append
- Migrated handleAppend to CmdAppend.
This commit is contained in:
@@ -142,7 +142,6 @@ void Cmd::load ()
|
|||||||
commands.push_back ("burndown.weekly");
|
commands.push_back ("burndown.weekly");
|
||||||
commands.push_back ("burndown.monthly");
|
commands.push_back ("burndown.monthly");
|
||||||
commands.push_back ("add");
|
commands.push_back ("add");
|
||||||
commands.push_back ("append");
|
|
||||||
commands.push_back ("annotate");
|
commands.push_back ("annotate");
|
||||||
commands.push_back ("denotate");
|
commands.push_back ("denotate");
|
||||||
commands.push_back ("calendar");
|
commands.push_back ("calendar");
|
||||||
@@ -247,7 +246,6 @@ bool Cmd::isWriteCommand ()
|
|||||||
{
|
{
|
||||||
if (command == "merge" ||
|
if (command == "merge" ||
|
||||||
command == "add" ||
|
command == "add" ||
|
||||||
command == "append" ||
|
|
||||||
command == "annotate" ||
|
command == "annotate" ||
|
||||||
command == "denotate" ||
|
command == "denotate" ||
|
||||||
command == "delete" ||
|
command == "delete" ||
|
||||||
|
|||||||
@@ -261,7 +261,6 @@ int Context::dispatch (std::string &out)
|
|||||||
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
|
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
|
||||||
else if (cmd.command == "add") { rc = handleAdd (out); }
|
else if (cmd.command == "add") { rc = handleAdd (out); }
|
||||||
else if (cmd.command == "log") { rc = handleLog (out); }
|
else if (cmd.command == "log") { rc = handleLog (out); }
|
||||||
else if (cmd.command == "append") { rc = handleAppend (out); }
|
|
||||||
else if (cmd.command == "annotate") { rc = handleAnnotate (out); }
|
else if (cmd.command == "annotate") { rc = handleAnnotate (out); }
|
||||||
else if (cmd.command == "denotate") { rc = handleDenotate (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); }
|
||||||
|
|||||||
@@ -1080,90 +1080,6 @@ int handleModify (std::string& outs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int handleAppend (std::string& outs)
|
|
||||||
{
|
|
||||||
if (!context.task.has ("description"))
|
|
||||||
throw std::string ("Additional text must be provided.");
|
|
||||||
|
|
||||||
int rc = 0;
|
|
||||||
int count = 0;
|
|
||||||
std::stringstream out;
|
|
||||||
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
Filter filter;
|
|
||||||
context.tdb.loadPending (tasks, filter);
|
|
||||||
|
|
||||||
// Filter sequence.
|
|
||||||
std::vector <Task> all = tasks;
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
foreach (other, all)
|
|
||||||
{
|
|
||||||
if (other->id == task->id || // Self
|
|
||||||
(task->has ("parent") &&
|
|
||||||
task->get ("parent") == other->get ("parent")) || // Sibling
|
|
||||||
other->get ("uuid") == task->get ("parent")) // Parent
|
|
||||||
{
|
|
||||||
Task before (*other);
|
|
||||||
|
|
||||||
// A non-zero value forces a file write.
|
|
||||||
int changes = 0;
|
|
||||||
|
|
||||||
// Apply other deltas.
|
|
||||||
changes += deltaAppend (*other);
|
|
||||||
changes += deltaTags (*other);
|
|
||||||
changes += deltaAttributes (*other);
|
|
||||||
changes += deltaSubstitutions (*other);
|
|
||||||
|
|
||||||
if (taskDiff (before, *other))
|
|
||||||
{
|
|
||||||
// Only allow valid tasks.
|
|
||||||
other->validate ();
|
|
||||||
|
|
||||||
if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?"))
|
|
||||||
{
|
|
||||||
context.tdb.update (*other);
|
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
|
||||||
out << "Appended '"
|
|
||||||
<< context.task.get ("description")
|
|
||||||
<< "' to task "
|
|
||||||
<< other->id
|
|
||||||
<< ".\n";
|
|
||||||
|
|
||||||
if (before.get ("project") != other->get ("project"))
|
|
||||||
context.footnote (onProjectChange (before, *other));
|
|
||||||
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
if (context.config.getBoolean ("echo.command"))
|
|
||||||
out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n");
|
|
||||||
|
|
||||||
outs = out.str ();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int handleDuplicate (std::string& outs)
|
int handleDuplicate (std::string& outs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ include_directories (${CMAKE_SOURCE_DIR}
|
|||||||
${TASK_INCLUDE_DIRS})
|
${TASK_INCLUDE_DIRS})
|
||||||
|
|
||||||
set (commands_SRCS Command.cpp Command.h
|
set (commands_SRCS Command.cpp Command.h
|
||||||
|
CmdAppend.cpp CmdAppend.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
|
||||||
|
|||||||
132
src/commands/CmdAppend.cpp
Normal file
132
src/commands/CmdAppend.cpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <main.h>
|
||||||
|
#include <CmdAppend.h>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CmdAppend::CmdAppend ()
|
||||||
|
{
|
||||||
|
_keyword = "append";
|
||||||
|
_usage = "task append <IDs> [tags] [attrs] desc...";
|
||||||
|
_description = "Append more description to an existing task.";
|
||||||
|
_read_only = false;
|
||||||
|
_displays_id = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int CmdAppend::execute (const std::string& command_line, std::string& output)
|
||||||
|
{
|
||||||
|
if (!context.task.has ("description"))
|
||||||
|
throw std::string ("Additional text must be provided.");
|
||||||
|
|
||||||
|
int rc = 0;
|
||||||
|
int count = 0;
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
Filter filter;
|
||||||
|
context.tdb.loadPending (tasks, filter);
|
||||||
|
|
||||||
|
// Filter sequence.
|
||||||
|
std::vector <Task> all = tasks;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
std::vector <Task>::iterator other;
|
||||||
|
for (other = all.begin (); other != all.end (); ++other)
|
||||||
|
{
|
||||||
|
if (other->id == task->id || // Self
|
||||||
|
(task->has ("parent") &&
|
||||||
|
task->get ("parent") == other->get ("parent")) || // Sibling
|
||||||
|
other->get ("uuid") == task->get ("parent")) // Parent
|
||||||
|
{
|
||||||
|
Task before (*other);
|
||||||
|
|
||||||
|
// A non-zero value forces a file write.
|
||||||
|
int changes = 0;
|
||||||
|
|
||||||
|
// Apply other deltas.
|
||||||
|
changes += deltaAppend (*other);
|
||||||
|
changes += deltaTags (*other);
|
||||||
|
changes += deltaAttributes (*other);
|
||||||
|
changes += deltaSubstitutions (*other);
|
||||||
|
|
||||||
|
if (taskDiff (before, *other))
|
||||||
|
{
|
||||||
|
// Only allow valid tasks.
|
||||||
|
other->validate ();
|
||||||
|
|
||||||
|
if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?"))
|
||||||
|
{
|
||||||
|
context.tdb.update (*other);
|
||||||
|
|
||||||
|
if (context.config.getBoolean ("echo.command"))
|
||||||
|
out << "Appended '"
|
||||||
|
<< context.task.get ("description")
|
||||||
|
<< "' to task "
|
||||||
|
<< other->id
|
||||||
|
<< ".\n";
|
||||||
|
|
||||||
|
if (before.get ("project") != other->get ("project"))
|
||||||
|
context.footnote (onProjectChange (before, *other));
|
||||||
|
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
if (context.config.getBoolean ("echo.command"))
|
||||||
|
out << "Appended " << count << " task" << (count == 1 ? ".\n" : "s.\n");
|
||||||
|
|
||||||
|
output = out.str ();
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
42
src/commands/CmdAppend.h
Normal file
42
src/commands/CmdAppend.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_CMDAPPEND
|
||||||
|
#define INCLUDED_CMDAPPEND
|
||||||
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <Command.h>
|
||||||
|
|
||||||
|
class CmdAppend : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CmdAppend ();
|
||||||
|
int execute (const std::string&, std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -96,10 +96,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
|
|||||||
view.set (row, 1, "task log [tags] [attrs] desc...");
|
view.set (row, 1, "task log [tags] [attrs] desc...");
|
||||||
view.set (row, 2, "Adds a new task that is already completed.");
|
view.set (row, 2, "Adds a new task that is already completed.");
|
||||||
|
|
||||||
row = view.addRow ();
|
|
||||||
view.set (row, 1, "task append ID [tags] [attrs] desc...");
|
|
||||||
view.set (row, 2, "Appends more description to an existing task.");
|
|
||||||
|
|
||||||
row = view.addRow ();
|
row = view.addRow ();
|
||||||
view.set (row, 1, "task annotate ID desc...");
|
view.set (row, 1, "task annotate ID desc...");
|
||||||
view.set (row, 2, "Adds an annotation to an existing task.");
|
view.set (row, 2, "Adds an annotation to an existing task.");
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <Command.h>
|
#include <Command.h>
|
||||||
|
#include <CmdAppend.h>
|
||||||
#include <CmdCommands.h>
|
#include <CmdCommands.h>
|
||||||
#include <CmdCount.h>
|
#include <CmdCount.h>
|
||||||
#include <CmdCustom.h>
|
#include <CmdCustom.h>
|
||||||
@@ -57,6 +58,7 @@ void Command::factory (std::map <std::string, Command*>& all)
|
|||||||
{
|
{
|
||||||
Command* c;
|
Command* c;
|
||||||
|
|
||||||
|
c = new CmdAppend (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionCommands (); all[c->keyword ()] = c;
|
c = new CmdCompletionCommands (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionIds (); all[c->keyword ()] = c;
|
c = new CmdCompletionIds (); all[c->keyword ()] = c;
|
||||||
c = new CmdCompletionProjects (); all[c->keyword ()] = c;
|
c = new CmdCompletionProjects (); all[c->keyword ()] = c;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ bool nag (Task&);
|
|||||||
// command.cpp
|
// command.cpp
|
||||||
int handleAdd (std::string&);
|
int handleAdd (std::string&);
|
||||||
int handleLog (std::string&);
|
int handleLog (std::string&);
|
||||||
int handleAppend (std::string&);
|
|
||||||
int handleDone (std::string&);
|
int handleDone (std::string&);
|
||||||
int handleModify (std::string&);
|
int handleModify (std::string&);
|
||||||
int handleCompletionConfig (std::string&);
|
int handleCompletionConfig (std::string&);
|
||||||
|
|||||||
Reference in New Issue
Block a user