mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
Enhanced export command
- Now sanitizes output by replacing ' with " in descriptions. - Added 'recur' attribute to exported output. - Removed recurring, deleted and complete tasks from the export.
This commit is contained in:
parent
8ac3978222
commit
5383943fa7
3 changed files with 24 additions and 5 deletions
11
src/T.cpp
11
src/T.cpp
|
@ -328,6 +328,11 @@ const std::string T::composeCSV ()
|
||||||
line += value;
|
line += value;
|
||||||
line += ",";
|
line += ",";
|
||||||
|
|
||||||
|
value = mAttributes["recur"];
|
||||||
|
if (value != "")
|
||||||
|
line += value;
|
||||||
|
line += ",";
|
||||||
|
|
||||||
value = mAttributes["end"];
|
value = mAttributes["end"];
|
||||||
if (value != "")
|
if (value != "")
|
||||||
line += value;
|
line += value;
|
||||||
|
@ -353,7 +358,11 @@ const std::string T::composeCSV ()
|
||||||
line += "'" + value + "'";
|
line += "'" + value + "'";
|
||||||
line += ",";
|
line += ",";
|
||||||
|
|
||||||
line += "'" + mDescription + "'\n";
|
// Convert single quotes to double quotes, because single quotes are used to
|
||||||
|
// delimit the values that need it.
|
||||||
|
std::string clean = mDescription;
|
||||||
|
std::replace (clean.begin (), clean.end (), '\'', '"');
|
||||||
|
line += "'" + clean + "'\n";
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
|
@ -578,7 +578,7 @@ std::string handleDone (TDB& tdb, T& task, Config& conf)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string handleExport (TDB& tdb, T& task, Config& conf)
|
std::string handleExport (TDB& tdb, T& task, Config& conf)
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream output;
|
||||||
|
|
||||||
// Use the description as a file name, then clobber the description so the
|
// Use the description as a file name, then clobber the description so the
|
||||||
// file name isn't used for filtering.
|
// file name isn't used for filtering.
|
||||||
|
@ -597,6 +597,7 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
|
||||||
<< "'entry',"
|
<< "'entry',"
|
||||||
<< "'start',"
|
<< "'start',"
|
||||||
<< "'due',"
|
<< "'due',"
|
||||||
|
<< "'recur',"
|
||||||
<< "'end',"
|
<< "'end',"
|
||||||
<< "'project',"
|
<< "'project',"
|
||||||
<< "'priority',"
|
<< "'priority',"
|
||||||
|
@ -605,14 +606,22 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
|
||||||
<< "'description'"
|
<< "'description'"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
std::vector <T> all;
|
std::vector <T> all;
|
||||||
tdb.allT (all);
|
tdb.allPendingT (all);
|
||||||
filter (all, task);
|
filter (all, task);
|
||||||
foreach (t, all)
|
foreach (t, all)
|
||||||
{
|
{
|
||||||
out << t->composeCSV ().c_str ();
|
if (t->getStatus () != T::recurring &&
|
||||||
|
t->getStatus () != T::deleted)
|
||||||
|
{
|
||||||
|
out << t->composeCSV ().c_str ();
|
||||||
|
++count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.close ();
|
out.close ();
|
||||||
|
|
||||||
|
output << count << " tasks exported to '" << file << "'" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw std::string ("Could not write to export file.");
|
throw std::string ("Could not write to export file.");
|
||||||
|
@ -620,7 +629,7 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
|
||||||
else
|
else
|
||||||
throw std::string ("You must specify a file to write to.");
|
throw std::string ("You must specify a file to write to.");
|
||||||
|
|
||||||
return out.str ();
|
return output.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -187,6 +187,7 @@ static char randomHexDigit ()
|
||||||
{
|
{
|
||||||
static char digits[] = "0123456789abcdef";
|
static char digits[] = "0123456789abcdef";
|
||||||
#ifdef HAVE_RANDOM
|
#ifdef HAVE_RANDOM
|
||||||
|
// random is better than rand.
|
||||||
return digits[random () % 16];
|
return digits[random () % 16];
|
||||||
#else
|
#else
|
||||||
return digits[rand () % 16];
|
return digits[rand () % 16];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue