mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Commands - add
- Migrated handleAdd to CmdAdd.
This commit is contained in:
parent
b0cbc7f757
commit
cb613c0691
12 changed files with 200 additions and 105 deletions
|
@ -362,6 +362,12 @@ void Arguments::extract_sequence (std::vector <int>& sequence)
|
|||
this->erase (this->begin () + kill[k]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO
|
||||
void Arguments::extract_nv ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO
|
||||
void Arguments::extract_uuids (std::vector <std::string>& uuids)
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
|
||||
bool extract_command (const std::vector <std::string>&, std::string&);
|
||||
void extract_sequence (std::vector <int>&);
|
||||
void extract_nv ();
|
||||
void extract_uuids (std::vector <std::string>&);
|
||||
void extract_filter ();
|
||||
void extract_modifications ();
|
||||
|
|
|
@ -134,7 +134,6 @@ void Cmd::load ()
|
|||
commands.push_back ("export.csv");
|
||||
commands.push_back ("export.ical");
|
||||
commands.push_back ("export.yaml");
|
||||
commands.push_back ("add");
|
||||
commands.push_back ("annotate");
|
||||
commands.push_back ("denotate");
|
||||
commands.push_back ("calendar");
|
||||
|
@ -231,7 +230,6 @@ bool Cmd::isReadOnlyCommand ()
|
|||
bool Cmd::isWriteCommand ()
|
||||
{
|
||||
if (command == "merge" ||
|
||||
command == "add" ||
|
||||
command == "annotate" ||
|
||||
command == "denotate" ||
|
||||
command == "delete" ||
|
||||
|
|
|
@ -252,7 +252,6 @@ int Context::dispatch (std::string &out)
|
|||
else if (cmd.command == "summary") { rc = handleReportSummary (out); }
|
||||
else if (cmd.command == "calendar") { rc = handleReportCalendar (out); }
|
||||
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
|
||||
else if (cmd.command == "add") { rc = handleAdd (out); }
|
||||
else if (cmd.command == "log") { rc = handleLog (out); }
|
||||
else if (cmd.command == "annotate") { rc = handleAnnotate (out); }
|
||||
else if (cmd.command == "denotate") { rc = handleDenotate (out); }
|
||||
|
|
|
@ -51,102 +51,6 @@
|
|||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleAdd (std::string& outs)
|
||||
{
|
||||
int rc = 0;
|
||||
std::stringstream out;
|
||||
|
||||
context.task.set ("uuid", uuid ());
|
||||
context.task.setEntry ();
|
||||
|
||||
// Recurring tasks get a special status.
|
||||
if (context.task.has ("due") &&
|
||||
context.task.has ("recur"))
|
||||
{
|
||||
context.task.setStatus (Task::recurring);
|
||||
context.task.set ("mask", "");
|
||||
}
|
||||
|
||||
// Tasks with a wait: date get a special status.
|
||||
else if (context.task.has ("wait"))
|
||||
context.task.setStatus (Task::waiting);
|
||||
|
||||
// By default, tasks are pending.
|
||||
else
|
||||
context.task.setStatus (Task::pending);
|
||||
|
||||
// Override with default.project, if not specified.
|
||||
if (context.task.get ("project") == "")
|
||||
context.task.set ("project", context.config.get ("default.project"));
|
||||
|
||||
// Override with default.priority, if not specified.
|
||||
if (context.task.get ("priority") == "")
|
||||
{
|
||||
std::string defaultPriority = context.config.get ("default.priority");
|
||||
if (Att::validNameValue ("priority", "", defaultPriority))
|
||||
context.task.set ("priority", defaultPriority);
|
||||
}
|
||||
|
||||
// Override with default.due, if not specified.
|
||||
if (context.task.get ("due") == "")
|
||||
{
|
||||
std::string defaultDue = context.config.get ("default.due");
|
||||
if (defaultDue != "" &&
|
||||
Att::validNameValue ("due", "", defaultDue))
|
||||
context.task.set ("due", defaultDue);
|
||||
}
|
||||
|
||||
// Include tags.
|
||||
foreach (tag, context.tagAdditions)
|
||||
context.task.addTag (*tag);
|
||||
|
||||
// Must load pending to resolve dependencies, and to provide a new ID.
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
std::vector <Task> all;
|
||||
Filter none;
|
||||
context.tdb.loadPending (all, none);
|
||||
|
||||
// Resolve dependencies.
|
||||
if (context.task.has ("depends"))
|
||||
{
|
||||
// Convert ID to UUID.
|
||||
std::vector <std::string> deps;
|
||||
split (deps, context.task.get ("depends"), ',');
|
||||
|
||||
// Eliminate the ID-based set.
|
||||
context.task.set ("depends", "");
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = deps.begin (); i != deps.end (); i++)
|
||||
{
|
||||
int id = atoi (i->c_str ());
|
||||
if (id < 0)
|
||||
context.task.removeDependency (-id);
|
||||
else
|
||||
context.task.addDependency (id);
|
||||
}
|
||||
}
|
||||
|
||||
// Only valid tasks can be added.
|
||||
context.task.validate ();
|
||||
|
||||
context.tdb.add (context.task);
|
||||
|
||||
#ifdef FEATURE_NEW_ID
|
||||
out << "Created task " << context.tdb.nextId () << ".\n";
|
||||
#endif
|
||||
|
||||
context.footnote (onProjectChange (context.task));
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
outs = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleLog (std::string& outs)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ include_directories (${CMAKE_SOURCE_DIR}
|
|||
${TASK_INCLUDE_DIRS})
|
||||
|
||||
set (commands_SRCS Command.cpp Command.h
|
||||
CmdAdd.cpp CmdAdd.h
|
||||
CmdAppend.cpp CmdAppend.h
|
||||
CmdBurndown.cpp CmdBurndown.h
|
||||
CmdCommands.cpp CmdCommands.h
|
||||
|
|
146
src/commands/CmdAdd.cpp
Normal file
146
src/commands/CmdAdd.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <text.h>
|
||||
#include <util.h>
|
||||
#include <main.h>
|
||||
#include <CmdAdd.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdAdd::CmdAdd ()
|
||||
{
|
||||
_keyword = "add";
|
||||
_usage = "task add [tags] [attrs] desc...";
|
||||
_description = "Adds a new task.";
|
||||
_read_only = false;
|
||||
_displays_id = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdAdd::execute (const std::string&, std::string& output)
|
||||
{
|
||||
int rc = 0;
|
||||
std::stringstream out;
|
||||
|
||||
context.task.set ("uuid", uuid ());
|
||||
context.task.setEntry ();
|
||||
|
||||
// Recurring tasks get a special status.
|
||||
if (context.task.has ("due") &&
|
||||
context.task.has ("recur"))
|
||||
{
|
||||
context.task.setStatus (Task::recurring);
|
||||
context.task.set ("mask", "");
|
||||
}
|
||||
|
||||
// Tasks with a wait: date get a special status.
|
||||
else if (context.task.has ("wait"))
|
||||
context.task.setStatus (Task::waiting);
|
||||
|
||||
// By default, tasks are pending.
|
||||
else
|
||||
context.task.setStatus (Task::pending);
|
||||
|
||||
// Override with default.project, if not specified.
|
||||
if (context.task.get ("project") == "")
|
||||
context.task.set ("project", context.config.get ("default.project"));
|
||||
|
||||
// Override with default.priority, if not specified.
|
||||
if (context.task.get ("priority") == "")
|
||||
{
|
||||
std::string defaultPriority = context.config.get ("default.priority");
|
||||
if (Att::validNameValue ("priority", "", defaultPriority))
|
||||
context.task.set ("priority", defaultPriority);
|
||||
}
|
||||
|
||||
// Override with default.due, if not specified.
|
||||
if (context.task.get ("due") == "")
|
||||
{
|
||||
std::string defaultDue = context.config.get ("default.due");
|
||||
if (defaultDue != "" &&
|
||||
Att::validNameValue ("due", "", defaultDue))
|
||||
context.task.set ("due", defaultDue);
|
||||
}
|
||||
|
||||
// Include tags.
|
||||
std::vector <std::string>::iterator tag;
|
||||
for (tag = context.tagAdditions.begin ();
|
||||
tag != context.tagAdditions.end ();
|
||||
++tag)
|
||||
context.task.addTag (*tag);
|
||||
|
||||
// Must load pending to resolve dependencies, and to provide a new ID.
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
std::vector <Task> all;
|
||||
Filter none;
|
||||
context.tdb.loadPending (all, none);
|
||||
|
||||
// Resolve dependencies.
|
||||
if (context.task.has ("depends"))
|
||||
{
|
||||
// Convert ID to UUID.
|
||||
std::vector <std::string> deps;
|
||||
split (deps, context.task.get ("depends"), ',');
|
||||
|
||||
// Eliminate the ID-based set.
|
||||
context.task.set ("depends", "");
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = deps.begin (); i != deps.end (); i++)
|
||||
{
|
||||
int id = atoi (i->c_str ());
|
||||
if (id < 0)
|
||||
context.task.removeDependency (-id);
|
||||
else
|
||||
context.task.addDependency (id);
|
||||
}
|
||||
}
|
||||
|
||||
// Only valid tasks can be added.
|
||||
context.task.validate ();
|
||||
|
||||
context.tdb.add (context.task);
|
||||
|
||||
#ifdef FEATURE_NEW_ID
|
||||
out << "Created task " << context.tdb.nextId () << ".\n";
|
||||
#endif
|
||||
|
||||
context.footnote (onProjectChange (context.task));
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
output = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
42
src/commands/CmdAdd.h
Normal file
42
src/commands/CmdAdd.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_CMDADD
|
||||
#define INCLUDED_CMDADD
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#include <string>
|
||||
#include <Command.h>
|
||||
|
||||
class CmdAdd : public Command
|
||||
{
|
||||
public:
|
||||
CmdAdd ();
|
||||
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 add [tags] [attrs] desc...");
|
||||
view.set (row, 2, "Adds a new task.");
|
||||
|
||||
row = view.addRow ();
|
||||
view.set (row, 1, "task log [tags] [attrs] desc...");
|
||||
view.set (row, 2, "Adds a new task that is already completed.");
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <Command.h>
|
||||
#include <CmdAdd.h>
|
||||
#include <CmdAppend.h>
|
||||
#include <CmdBurndown.h>
|
||||
#include <CmdCommands.h>
|
||||
|
@ -60,6 +61,7 @@ void Command::factory (std::map <std::string, Command*>& all)
|
|||
{
|
||||
Command* c;
|
||||
|
||||
c = new CmdAdd (); all[c->keyword ()] = c;
|
||||
c = new CmdAppend (); all[c->keyword ()] = c;
|
||||
c = new CmdBurndownDaily (); all[c->keyword ()] = c;
|
||||
c = new CmdBurndownMonthly (); all[c->keyword ()] = c;
|
||||
|
|
|
@ -705,7 +705,8 @@ static std::string importTaskCmdLine (const std::vector <std::string>& lines)
|
|||
context.task.clear ();
|
||||
context.cmd.command = "";
|
||||
context.parse ();
|
||||
(void)handleAdd (unused);
|
||||
// (void)handleAdd (unused);
|
||||
context.commands["add"]->execute (unused, unused);
|
||||
context.clearMessages ();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ int getDueState (const std::string&);
|
|||
bool nag (Task&);
|
||||
|
||||
// command.cpp
|
||||
int handleAdd (std::string&);
|
||||
int handleLog (std::string&);
|
||||
int handleDone (std::string&);
|
||||
int handleModify (std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue