mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +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.
|
// 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 (); }
|
if (cmd.command == "projects") { out = handleProjects (); }
|
||||||
else if (cmd.command == "tags") { out = handleTags (); }
|
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 == "start") { out = handleStart (); }
|
||||||
else if (cmd.command == "stop") { out = handleStop (); }
|
else if (cmd.command == "stop") { out = handleStop (); }
|
||||||
else if (cmd.command == "undo") { out = handleUndo (); }
|
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 == "import") { out = handleImport (); }
|
||||||
else if (cmd.command == "duplicate") { out = handleDuplicate (); }
|
else if (cmd.command == "duplicate") { out = handleDuplicate (); }
|
||||||
else if (cmd.command == "edit") { out = handleEdit (); }
|
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 ()
|
std::string Task::composeCSV ()
|
||||||
{
|
{
|
||||||
throw std::string ("unimplemented Task::composeCSV");
|
std::stringstream out;
|
||||||
return "";
|
|
||||||
|
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,58 +639,44 @@ std::string handleDone ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string handleExport ()
|
std::string handleExport ()
|
||||||
{
|
{
|
||||||
std::stringstream output;
|
std::stringstream out;
|
||||||
/*
|
|
||||||
// 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 ("");
|
|
||||||
|
|
||||||
if (file.length () > 0)
|
out << "'id',"
|
||||||
|
<< "'uuid',"
|
||||||
|
<< "'status',"
|
||||||
|
<< "'tags',"
|
||||||
|
<< "'entry',"
|
||||||
|
<< "'start',"
|
||||||
|
<< "'due',"
|
||||||
|
<< "'recur',"
|
||||||
|
<< "'end',"
|
||||||
|
<< "'project',"
|
||||||
|
<< "'priority',"
|
||||||
|
<< "'fg',"
|
||||||
|
<< "'bg',"
|
||||||
|
<< "'description'"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
// 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)
|
||||||
{
|
{
|
||||||
std::ofstream out (file.c_str ());
|
if (task->getStatus () != Task::recurring &&
|
||||||
if (out.good ())
|
task->getStatus () != Task::deleted)
|
||||||
{
|
{
|
||||||
out << "'id',"
|
out << task->composeCSV ().c_str ();
|
||||||
<< "'uuid',"
|
++count;
|
||||||
<< "'status',"
|
|
||||||
<< "'tags',"
|
|
||||||
<< "'entry',"
|
|
||||||
<< "'start',"
|
|
||||||
<< "'due',"
|
|
||||||
<< "'recur',"
|
|
||||||
<< "'end',"
|
|
||||||
<< "'project',"
|
|
||||||
<< "'priority',"
|
|
||||||
<< "'fg',"
|
|
||||||
<< "'bg',"
|
|
||||||
<< "'description'"
|
|
||||||
<< "\n";
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
std::vector <T> all;
|
|
||||||
tdb.allPendingT (all);
|
|
||||||
filter (all, task);
|
|
||||||
foreach (t, all)
|
|
||||||
{
|
|
||||||
if (t->getStatus () != T::recurring &&
|
|
||||||
t->getStatus () != T::deleted)
|
|
||||||
{
|
|
||||||
out << t->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 out.str ();
|
||||||
*/
|
|
||||||
return output.str ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -174,7 +174,7 @@ std::string shortUsage ()
|
||||||
|
|
||||||
row = table.addRow ();
|
row = table.addRow ();
|
||||||
table.addCell (row, 1, "task export");
|
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 ();
|
row = table.addRow ();
|
||||||
table.addCell (row, 1, "task color");
|
table.addCell (row, 1, "task color");
|
||||||
|
@ -274,6 +274,7 @@ std::string handleInfo ()
|
||||||
context.tdb.lock (context.config.get ("locking", true));
|
context.tdb.lock (context.config.get ("locking", true));
|
||||||
context.tdb.loadPending (tasks, context.filter);
|
context.tdb.loadPending (tasks, context.filter);
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
// TODO handleRecurrence (tdb, tasks);
|
||||||
|
|
||||||
// Filter sequence.
|
// Filter sequence.
|
||||||
context.filter.applySequence (tasks, context.sequence);
|
context.filter.applySequence (tasks, context.sequence);
|
||||||
|
@ -1615,6 +1616,7 @@ std::string handleReportStats ()
|
||||||
context.tdb.lock (context.config.get ("locking", true));
|
context.tdb.lock (context.config.get ("locking", true));
|
||||||
context.tdb.load (tasks, context.filter);
|
context.tdb.load (tasks, context.filter);
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
// TODO handleRecurrence (tdb, tasks);
|
||||||
|
|
||||||
Date now;
|
Date now;
|
||||||
time_t earliest = time (NULL);
|
time_t earliest = time (NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue