mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 13:37:20 +02:00
Enhancements - export
- Implemented Task::composeCSV. - Implemented export command, but removed filename support. This needs to be documented.
This commit is contained in:
parent
efe0b86708
commit
f470acadaa
4 changed files with 69 additions and 51 deletions
|
@ -164,7 +164,6 @@ std::string Context::dispatch ()
|
|||
|
||||
// TODO Look at this thing. It just cries out for a dispatch table.
|
||||
/*
|
||||
if (cmd.command == "export") { out = handleExport (); }
|
||||
*/
|
||||
if (cmd.command == "projects") { out = handleProjects (); }
|
||||
else if (cmd.command == "tags") { out = handleTags (); }
|
||||
|
@ -191,6 +190,9 @@ std::string Context::dispatch ()
|
|||
else if (cmd.command == "start") { out = handleStart (); }
|
||||
else if (cmd.command == "stop") { out = handleStop (); }
|
||||
else if (cmd.command == "undo") { out = handleUndo (); }
|
||||
*/
|
||||
else if (cmd.command == "export") { out = handleExport (); }
|
||||
/*
|
||||
else if (cmd.command == "import") { out = handleImport (); }
|
||||
else if (cmd.command == "duplicate") { out = handleDuplicate (); }
|
||||
else if (cmd.command == "edit") { out = handleEdit (); }
|
||||
|
|
32
src/Task.cpp
32
src/Task.cpp
|
@ -298,8 +298,36 @@ void Task::legacyParse (const std::string& line)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Task::composeCSV ()
|
||||
{
|
||||
throw std::string ("unimplemented Task::composeCSV");
|
||||
return "";
|
||||
std::stringstream out;
|
||||
|
||||
out << "'" << id << "',";
|
||||
out << "'" << get ("uuid") << "',";
|
||||
out << "'" << get ("status") << "',";
|
||||
|
||||
// Tags
|
||||
std::vector <std::string> tags;
|
||||
getTags (tags);
|
||||
std::string allTags;
|
||||
join (allTags, " ", tags);
|
||||
out << "'" << allTags << "',";
|
||||
|
||||
out << "'" << get ("entry") << "',";
|
||||
out << "'" << get ("start") << "',";
|
||||
out << "'" << get ("due") << "',";
|
||||
out << "'" << get ("recur") << "',";
|
||||
out << "'" << get ("end") << "',";
|
||||
out << "'" << get ("project") << "',";
|
||||
out << "'" << get ("priority") << "',";
|
||||
out << "'" << get ("fg") << "',";
|
||||
out << "'" << get ("bg") << "',";
|
||||
|
||||
// Convert single quotes to double quotes, because single quotes are used to
|
||||
// delimit the values that need it.
|
||||
std::string clean = get ("description");
|
||||
std::replace (clean.begin (), clean.end (), '\'', '"');
|
||||
out << "'" << clean << "'\n";
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -639,18 +639,8 @@ std::string handleDone ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string handleExport ()
|
||||
{
|
||||
std::stringstream output;
|
||||
/*
|
||||
// Use the description as a file name, then clobber the description so the
|
||||
// file name isn't used for filtering.
|
||||
std::string file = trim (task.getDescription ());
|
||||
task.setDescription ("");
|
||||
std::stringstream out;
|
||||
|
||||
if (file.length () > 0)
|
||||
{
|
||||
std::ofstream out (file.c_str ());
|
||||
if (out.good ())
|
||||
{
|
||||
out << "'id',"
|
||||
<< "'uuid',"
|
||||
<< "'status',"
|
||||
|
@ -668,29 +658,25 @@ std::string handleExport ()
|
|||
<< "\n";
|
||||
|
||||
int count = 0;
|
||||
std::vector <T> all;
|
||||
tdb.allPendingT (all);
|
||||
filter (all, task);
|
||||
foreach (t, all)
|
||||
|
||||
// Get all the tasks.
|
||||
std::vector <Task> tasks;
|
||||
context.tdb.lock (context.config.get ("locking", true));
|
||||
context.tdb.loadPending (tasks, context.filter);
|
||||
context.tdb.unlock ();
|
||||
// TODO handleRecurrence (tdb, tasks);
|
||||
|
||||
foreach (task, tasks)
|
||||
{
|
||||
if (t->getStatus () != T::recurring &&
|
||||
t->getStatus () != T::deleted)
|
||||
if (task->getStatus () != Task::recurring &&
|
||||
task->getStatus () != Task::deleted)
|
||||
{
|
||||
out << t->composeCSV ().c_str ();
|
||||
out << task->composeCSV ().c_str ();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
out.close ();
|
||||
|
||||
output << count << " tasks exported to '" << file << "'" << std::endl;
|
||||
}
|
||||
else
|
||||
throw std::string ("Could not write to export file.");
|
||||
}
|
||||
else
|
||||
throw std::string ("You must specify a file to write to.");
|
||||
*/
|
||||
return output.str ();
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -174,7 +174,7 @@ std::string shortUsage ()
|
|||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task export");
|
||||
table.addCell (row, 2, "Exports all tasks as a CSV file");
|
||||
table.addCell (row, 2, "Lists all tasks as a CSV file");
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 1, "task color");
|
||||
|
@ -274,6 +274,7 @@ std::string handleInfo ()
|
|||
context.tdb.lock (context.config.get ("locking", true));
|
||||
context.tdb.loadPending (tasks, context.filter);
|
||||
context.tdb.unlock ();
|
||||
// TODO handleRecurrence (tdb, tasks);
|
||||
|
||||
// Filter sequence.
|
||||
context.filter.applySequence (tasks, context.sequence);
|
||||
|
@ -1615,6 +1616,7 @@ std::string handleReportStats ()
|
|||
context.tdb.lock (context.config.get ("locking", true));
|
||||
context.tdb.load (tasks, context.filter);
|
||||
context.tdb.unlock ();
|
||||
// TODO handleRecurrence (tdb, tasks);
|
||||
|
||||
Date now;
|
||||
time_t earliest = time (NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue