mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - export.yaml
- Preliminary export.yaml support. No unit tests yet, and no decision on including this feature. It may be that libyaml is the right choice, as an optional dependency.
This commit is contained in:
parent
8b02d2bdeb
commit
2b48ae8e38
6 changed files with 67 additions and 10 deletions
|
@ -115,6 +115,7 @@ void Cmd::load ()
|
||||||
commands.push_back ("_merge");
|
commands.push_back ("_merge");
|
||||||
commands.push_back ("export.csv");
|
commands.push_back ("export.csv");
|
||||||
commands.push_back ("export.ical");
|
commands.push_back ("export.ical");
|
||||||
|
commands.push_back ("export.yaml");
|
||||||
commands.push_back ("history.monthly");
|
commands.push_back ("history.monthly");
|
||||||
commands.push_back ("history.annual");
|
commands.push_back ("history.annual");
|
||||||
commands.push_back ("ghistory.monthly");
|
commands.push_back ("ghistory.monthly");
|
||||||
|
@ -207,6 +208,7 @@ bool Cmd::isReadOnlyCommand ()
|
||||||
command == "_version" ||
|
command == "_version" ||
|
||||||
command == "export.csv" ||
|
command == "export.csv" ||
|
||||||
command == "export.ical" ||
|
command == "export.ical" ||
|
||||||
|
command == "export.yaml" ||
|
||||||
command == "history.monthly" ||
|
command == "history.monthly" ||
|
||||||
command == "history.annual" ||
|
command == "history.annual" ||
|
||||||
command == "ghistory.monthly" ||
|
command == "ghistory.monthly" ||
|
||||||
|
|
|
@ -233,6 +233,7 @@ int Context::dispatch (std::string &out)
|
||||||
else if (cmd.command == "stop") { rc = handleStop (out); }
|
else if (cmd.command == "stop") { rc = handleStop (out); }
|
||||||
else if (cmd.command == "export.csv") { rc = handleExportCSV (out); }
|
else if (cmd.command == "export.csv") { rc = handleExportCSV (out); }
|
||||||
else if (cmd.command == "export.ical") { rc = handleExportiCal (out); }
|
else if (cmd.command == "export.ical") { rc = handleExportiCal (out); }
|
||||||
|
else if (cmd.command == "export.yaml") { rc = handleExportYAML (out); }
|
||||||
else if (cmd.command == "import") { rc = handleImport (out); }
|
else if (cmd.command == "import") { rc = handleImport (out); }
|
||||||
else if (cmd.command == "duplicate") { rc = handleDuplicate (out); }
|
else if (cmd.command == "duplicate") { rc = handleDuplicate (out); }
|
||||||
else if (cmd.command == "edit") { rc = handleEdit (out); }
|
else if (cmd.command == "edit") { rc = handleEdit (out); }
|
||||||
|
|
29
src/Task.cpp
29
src/Task.cpp
|
@ -1,7 +1,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// task - a command line task list manager.
|
// task - a command line task list manager.
|
||||||
//
|
//
|
||||||
// Copyright 2006 - 2010, Paul Beckingham.
|
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify it under
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
@ -392,6 +392,33 @@ std::string Task::composeCSV () const
|
||||||
return out.str ();
|
return out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
std::string Task::composeYAML () const
|
||||||
|
{
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
// Task header.
|
||||||
|
out << " task:\n";
|
||||||
|
|
||||||
|
// Get all the supported attribute names.
|
||||||
|
std::vector <std::string> names;
|
||||||
|
Att::allNames (names);
|
||||||
|
std::sort (names.begin (), names.end ());
|
||||||
|
|
||||||
|
foreach (name, names)
|
||||||
|
out << " " << *name << ": " << get (*name) << "\n";
|
||||||
|
|
||||||
|
// Now the annotations, which are not listed by the Att::allNames call.
|
||||||
|
std::vector <Att> annotations;
|
||||||
|
getAnnotations (annotations);
|
||||||
|
foreach (a, annotations)
|
||||||
|
out << " annotation:\n"
|
||||||
|
<< " entry: " << a->name().substr (12) << "\n"
|
||||||
|
<< " description: " << a->value () << "\n";
|
||||||
|
|
||||||
|
return out.str ();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Task::getAnnotations (std::vector <Att>& annotations) const
|
void Task::getAnnotations (std::vector <Att>& annotations) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// task - a command line task list manager.
|
// task - a command line task list manager.
|
||||||
//
|
//
|
||||||
// Copyright 2006 - 2010, Paul Beckingham.
|
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify it under
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
void parse (const std::string&);
|
void parse (const std::string&);
|
||||||
std::string composeCSV () const;
|
std::string composeCSV () const;
|
||||||
|
std::string composeYAML () const;
|
||||||
|
|
||||||
// Status values.
|
// Status values.
|
||||||
enum status {pending, completed, deleted, recurring, waiting};
|
enum status {pending, completed, deleted, recurring, waiting};
|
||||||
|
|
|
@ -62,8 +62,6 @@ int handleExportCSV (std::string &outs)
|
||||||
<< "'description'"
|
<< "'description'"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
// Get all the tasks.
|
// Get all the tasks.
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
@ -77,10 +75,7 @@ int handleExportCSV (std::string &outs)
|
||||||
context.hooks.trigger ("pre-display", *task);
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
|
||||||
if (task->getStatus () != Task::recurring)
|
if (task->getStatus () != Task::recurring)
|
||||||
{
|
|
||||||
out << task->composeCSV ().c_str ();
|
out << task->composeCSV ().c_str ();
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outs = out.str ();
|
outs = out.str ();
|
||||||
|
@ -106,8 +101,6 @@ int handleExportiCal (std::string &outs)
|
||||||
<< "VERSION:2.0\n"
|
<< "VERSION:2.0\n"
|
||||||
<< "PRODID:-//GBF//" << PACKAGE_STRING << "//EN\n";
|
<< "PRODID:-//GBF//" << PACKAGE_STRING << "//EN\n";
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
// Get all the tasks.
|
// Get all the tasks.
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
@ -214,7 +207,6 @@ int handleExportiCal (std::string &outs)
|
||||||
out << "COMMENT:" << anno->value () << "\n";
|
out << "COMMENT:" << anno->value () << "\n";
|
||||||
|
|
||||||
out << "END:VTODO\n";
|
out << "END:VTODO\n";
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,3 +220,36 @@ int handleExportiCal (std::string &outs)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int handleExportYAML (std::string &outs)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (context.hooks.trigger ("pre-export-command"))
|
||||||
|
{
|
||||||
|
// YAML header.
|
||||||
|
std::stringstream out;
|
||||||
|
out << "%YAML 1.1\n"
|
||||||
|
<< "---\n";
|
||||||
|
|
||||||
|
// Get all the tasks.
|
||||||
|
std::vector <Task> tasks;
|
||||||
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
|
handleRecurrence ();
|
||||||
|
context.tdb.load (tasks, context.filter);
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
foreach (task, tasks)
|
||||||
|
{
|
||||||
|
context.hooks.trigger ("pre-display", *task);
|
||||||
|
out << task->composeYAML ().c_str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
outs = out.str ();
|
||||||
|
context.hooks.trigger ("post-export-command");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -133,6 +133,7 @@ int handleImport (std::string&);
|
||||||
// export.cpp
|
// export.cpp
|
||||||
int handleExportCSV (std::string &);
|
int handleExportCSV (std::string &);
|
||||||
int handleExportiCal (std::string &);
|
int handleExportiCal (std::string &);
|
||||||
|
int handleExportYAML (std::string &);
|
||||||
|
|
||||||
// list template
|
// list template
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue