Commands - export

- The default export format is now JSON, with an alias that maps 'export'
  to '_query'.
This commit is contained in:
Paul Beckingham 2011-05-30 11:42:35 -04:00
parent 6cf7644e02
commit 37b48c56d5
8 changed files with 4 additions and 255 deletions

View file

@ -33,6 +33,7 @@
+ The 'verbose' configuration variable now accepts a specific list of items to
be verbose about. See taskrc(5).
+ New 'execute' command that runs external programs.
+ The default export format is now JSON.
# Tracked Features, sorted by ID.
+ Added feature #330, which supports the 'inverse' color attribute.

2
NEWS
View file

@ -17,6 +17,7 @@ New Features in taskwarrior 2.0.0
- New 'next' report, that gauges urgency and reports the most urgent tasks.
- Fine control of verbosity through the 'verbose=' configuration variable.
- New 'execute' command that runs external scripts/programs.
- JSON is the new default export format.
Please refer to the ChangeLog file for full details. There are too many to
list here.
@ -39,6 +40,7 @@ New configuration options in taskwarrior 2.0.0
- New 'indent.annotation' for the description.default field format.
- New 'color.label' for report column labels.
- New 'verbose=...' support for individual verbosity settings.
- New 'avoidlastcolumn' support for Cygwin users.
Newly deprecated features in taskwarrior 2.0.0

View file

@ -42,7 +42,6 @@ set (task_SRCS API.cpp API.h
ViewText.cpp ViewText.h
command.cpp
dependency.cpp
export.cpp
feedback.cpp
i18n.h
import.cpp

View file

@ -130,9 +130,6 @@ void Cmd::load ()
if (commands.size () == 0)
{
commands.push_back ("_query");
commands.push_back ("export.csv");
commands.push_back ("export.ical");
commands.push_back ("export.yaml");
commands.push_back ("calendar");
commands.push_back ("delete");
commands.push_back ("done");
@ -201,9 +198,6 @@ void Cmd::allCommands (std::vector <std::string>& all) const
bool Cmd::isReadOnlyCommand ()
{
if (command == "_query" ||
command == "export.csv" ||
command == "export.ical" ||
command == "export.yaml" ||
command == "calendar" ||
command == "push" ||
command == "summary" ||

View file

@ -295,7 +295,7 @@ std::string Config::defaults =
"alias.rm=delete # Alias for the delete command\n"
"alias.history=history.monthly # Prefer monthly over annual history reports\n"
"alias.ghistory=ghistory.monthly # Prefer monthly graphical over annual history reports\n"
"alias.export=export.yaml # Prefer YAML over CSV or iCal export\n"
"alias.export=_query # Prefer JSON as the prime format\n"
"alias.export.vcalendar=export.ical # They are the same\n"
"alias.export.json=_query # The _query command will be used for all export\n"
"alias.burndown=burndown.weekly # Prefer the weekly burndown chart\n"

View file

@ -252,9 +252,6 @@ int Context::dispatch (std::string &out)
else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); }
else if (cmd.command == "done") { rc = handleDone (out); }
else if (cmd.command == "delete") { rc = handleDelete (out); }
else if (cmd.command == "export.csv") { rc = handleExportCSV (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 == "duplicate") { rc = handleDuplicate (out); }
else if (cmd.command == "undo") { handleUndo ( ); }

View file

@ -1,239 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// 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 <iostream>
#include <sstream>
#include <stdlib.h>
#include <Att.h>
#include <text.h>
#include <util.h>
#include <main.h>
#include <cmake.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
int handleExportCSV (std::string& outs)
{
int rc = 0;
std::stringstream out;
// Deliberately no 'id'.
out << "'uuid',"
<< "'status',"
<< "'tags',"
<< "'entry',"
<< "'start',"
<< "'due',"
<< "'recur',"
<< "'end',"
<< "'project',"
<< "'priority',"
<< "'fg',"
<< "'bg',"
<< "'description'"
<< "\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)
if (task->getStatus () != Task::recurring)
out << task->composeCSV ().c_str ();
outs = out.str ();
// Prevent messages from cluttering the export output.
context.headers.clear ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
// http://tools.ietf.org/html/rfc5545
//
// Note: Recurring tasks could be included in more detail.
int handleExportiCal (std::string& outs)
{
int rc = 0;
std::stringstream out;
out << "BEGIN:VCALENDAR\n"
<< "VERSION:2.0\n"
<< "PRODID:-//GBF//" << PACKAGE_STRING << "//EN\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)
{
if (task->getStatus () != Task::recurring)
{
out << "BEGIN:VTODO\n";
// Required UID:20070313T123432Z-456553@example.com
out << "UID:" << task->get ("uuid") << "\n";
// Required DTSTAMP:20070313T123432Z
Date entry (atoi (task->get ("entry").c_str ()));
out << "DTSTAMP:" << entry.toISO () << "\n";
// Optional DTSTART:20070514T110000Z
if (task->has ("start"))
{
Date start (atoi (task->get ("start").c_str ()));
out << "DTSTART:" << start.toISO () << "\n";
}
// Optional DUE:20070709T130000Z
if (task->has ("due"))
{
Date due (atoi (task->get ("due").c_str ()));
out << "DUE:" << due.toISO () << "\n";
}
// Optional COMPLETED:20070707T100000Z
if (task->has ("end") && task->getStatus () == Task::completed)
{
Date end (atoi (task->get ("end").c_str ()));
out << "COMPLETED:" << end.toISO () << "\n";
}
out << "SUMMARY:" << task->get ("description") << "\n";
// Optional CLASS:PUBLIC/PRIVATE/CONFIDENTIAL
std::string classification = context.config.get ("export.ical.class");
if (classification == "")
classification = "PRIVATE";
out << "CLASS:" << classification << "\n";
// Optional multiple CATEGORIES:FAMILY,FINANCE
if (task->getTagCount () > 0)
{
std::vector <std::string> tags;
task->getTags (tags);
std::string all;
join (all, ",", tags);
out << "CATEGORIES:" << all << "\n";
}
// Optional PRIORITY:
// 1-4 H
// 5 M
// 6-9 L
if (task->has ("priority"))
{
out << "PRIORITY:";
std::string priority = task->get ("priority");
if (priority == "H") out << "1";
else if (priority == "M") out << "5";
else out << "9";
out << "\n";
}
// Optional STATUS:NEEDS-ACTION/IN-PROCESS/COMPLETED/CANCELLED
out << "STATUS:";
Task::status stat = task->getStatus ();
if (stat == Task::pending || stat == Task::waiting)
{
if (task->has ("start"))
out << "IN-PROCESS";
else
out << "NEEDS-ACTION";
}
else if (stat == Task::completed)
{
out << "COMPLETED";
}
else if (stat == Task::deleted)
{
out << "CANCELLED";
}
out << "\n";
// Optional COMMENT:annotation1
// Optional COMMENT:annotation2
std::vector <Att> annotations;
task->getAnnotations (annotations);
foreach (anno, annotations)
out << "COMMENT:" << anno->value () << "\n";
out << "END:VTODO\n";
}
}
out << "END:VCALENDAR\n";
outs = out.str ();
// Prevent messages from cluttering the export output.
context.headers.clear ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleExportYAML (std::string& outs)
{
int rc = 0;
// 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)
out << task->composeYAML ().c_str ();
out << "...\n";
outs = out.str ();
// Prevent messages from cluttering the export output.
context.headers.clear ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -90,11 +90,6 @@ std::string colorizeDebug (const std::string&);
// import.cpp
int handleImport (std::string&);
// export.cpp
int handleExportCSV (std::string&);
int handleExportiCal (std::string&);
int handleExportYAML (std::string&);
// dependency.cpp
bool dependencyIsBlocked (const Task&);
void dependencyGetBlocked (const Task&, std::vector <Task>&);