diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 452b00acd..852b59f8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,6 @@ set (task_SRCS API.cpp API.h dependency.cpp feedback.cpp i18n.h - import.cpp interactive.cpp recur.cpp report.cpp diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 43332e16c..9a6c999f7 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -132,7 +132,6 @@ void Cmd::load () commands.push_back ("calendar"); commands.push_back ("delete"); commands.push_back ("done"); - commands.push_back ("import"); commands.push_back ("timesheet"); commands.push_back ("undo"); commands.push_back ("merge"); @@ -210,7 +209,6 @@ bool Cmd::isWriteCommand () if (command == "merge" || command == "delete" || command == "done" || - command == "import" || command == "pull" || command == "undo") return true; diff --git a/src/Context.cpp b/src/Context.cpp index 28a404a4b..fff1d5b55 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -253,7 +253,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 == "import") { rc = handleImport (out); } else if (cmd.command == "undo") { handleUndo ( ); } else if (cmd.command == "merge") { tdb.gc (); handleMerge (out); } diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index ceb48f049..820d4c970 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -23,6 +23,7 @@ set (commands_SRCS Command.cpp Command.h CmdHelp.cpp CmdHelp.h CmdHistory.cpp CmdHistory.h CmdIDs.cpp CmdIDs.h + CmdImport.cpp CmdImport.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h CmdLog.cpp CmdLog.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index fb64b9f1a..00b1be8a9 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -123,26 +123,6 @@ int CmdHelp::execute (const std::string&, std::string& output) view.set (row, 1, "task calendar [due|month year|year]"); view.set (row, 2, "Shows a calendar, with due tasks marked."); - row = view.addRow (); - view.set (row, 1, "task import"); - view.set (row, 2, "Imports tasks from a variety of formats."); - - row = view.addRow (); - view.set (row, 1, "task export"); - view.set (row, 2, "Lists all tasks in CSV format. Alias to export.csv"); - - row = view.addRow (); - view.set (row, 1, "task export.csv"); - view.set (row, 2, "Lists all tasks in CSV format."); - - row = view.addRow (); - view.set (row, 1, "task export.ical"); - view.set (row, 2, "Lists all tasks in iCalendar format."); - - row = view.addRow (); - view.set (row, 1, "task export.yaml"); - view.set (row, 2, "Lists all tasks in YAML format."); - row = view.addRow (); view.set (row, 1, "task merge URL"); view.set (row, 2, "Merges the specified undo.data file with the local data files."); diff --git a/src/import.cpp b/src/commands/CmdImport.cpp similarity index 92% rename from src/import.cpp rename to src/commands/CmdImport.cpp index ddac0a6f3..f3a09ea14 100644 --- a/src/import.cpp +++ b/src/commands/CmdImport.cpp @@ -24,35 +24,29 @@ // USA // //////////////////////////////////////////////////////////////////////////////// -#include + #include -#include -#include -#include -#include -#include +#include +#include #include #include #include -#include +#include extern Context context; //////////////////////////////////////////////////////////////////////////////// -enum fileType +CmdImport::CmdImport () { - not_a_clue, - task_1_4_3, - task_1_5_0, - task_1_6_0, - task_cmd_line, - todo_sh_2_0, - csv, - yaml, - text -}; + _keyword = "import"; + _usage = "task import "; + _description = "Imports tasks from a variety of formats."; + _read_only = false; + _displays_id = false; +} -static fileType determineFileType (const std::vector & lines) +//////////////////////////////////////////////////////////////////////////////// +CmdImport::fileType CmdImport::determineFileType (const std::vector & lines) { // '7f7a4191-c2f2-487f-8855-7a1eb378c267',' ... // ....:....|....:....|....:....|....:....| @@ -69,15 +63,15 @@ static fileType determineFileType (const std::vector & lines) { if (lines[0] == "'uuid','status','tags','entry','start','due','recur'," "'end','project','priority','fg','bg','description'") - return task_1_6_0; + return type_task_1_6_0; if (lines[0] == "'id','uuid','status','tags','entry','start','due','recur'," "'end','project','priority','fg','bg','description'") - return task_1_5_0; + return type_task_1_5_0; if (lines[0] == "'id','status','tags','entry','start','due','end','project'," "'priority','fg','bg','description'") - return task_1_4_3; + return type_task_1_4_3; } if ((lines.size () > 2 && @@ -90,7 +84,7 @@ static fileType determineFileType (const std::vector & lines) lines[2].find ("task:") != std::string::npos || lines[3].find ("task:") != std::string::npos))) { - return yaml; + return type_yaml; } // A task command line might include a priority or project. @@ -111,7 +105,7 @@ static fileType determineFileType (const std::vector & lines) words[w].substr (0, 6) == "proje:" || words[w].substr (0, 5) == "proj:" || words[w].substr (0, 4) == "pro:") - return task_cmd_line; + return type_task_cmd_line; } // x 2009-03-25 Walk the dog +project @context @@ -133,7 +127,7 @@ static fileType determineFileType (const std::vector & lines) lines[i][9] == '-' && isdigit (lines[i][10]) && isdigit (lines[i][11])) - return todo_sh_2_0; + return type_todo_sh_2_0; } std::vector words; @@ -144,13 +138,13 @@ static fileType determineFileType (const std::vector & lines) if (words[w].length () > 1 && words[w][0] == '+' && !isspace (words[w][1])) - return todo_sh_2_0; + return type_todo_sh_2_0; // @context if (words[w].length () > 1 && words[w][0] == '@' && !isspace (words[w][1])) - return todo_sh_2_0; + return type_todo_sh_2_0; } } @@ -166,17 +160,17 @@ static fileType determineFileType (const std::vector & lines) } } if (commas_on_every_line) - return csv; + return type_csv; // Looks like 'text' is the default case, if there is any data at all. if (lines.size () >= 1) - return text; + return type_text; - return not_a_clue; + return type_not_a_clue; } //////////////////////////////////////////////////////////////////////////////// -static void decorateTask (Task& task) +void CmdImport::decorateTask (Task& task) { if (!task.has ("entry")) { @@ -208,7 +202,7 @@ static void decorateTask (Task& task) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_4_3 (const std::vector & lines) +std::string CmdImport::task_1_4_3 (const std::vector & lines) { std::vector failed; @@ -364,7 +358,7 @@ static std::string importTask_1_4_3 (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_5_0 (const std::vector & lines) +std::string CmdImport::task_1_5_0 (const std::vector & lines) { std::vector failed; @@ -525,7 +519,7 @@ static std::string importTask_1_5_0 (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_6_0 (const std::vector & lines) +std::string CmdImport::task_1_6_0 (const std::vector & lines) { std::vector failed; @@ -687,7 +681,7 @@ static std::string importTask_1_6_0 (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTaskCmdLine (const std::vector & lines) +std::string CmdImport::taskCmdLine (const std::vector & lines) { std::vector failed; std::string unused; @@ -735,7 +729,7 @@ static std::string importTaskCmdLine (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTodoSh_2_0 (const std::vector & lines) +std::string CmdImport::todoSh_2_0 (const std::vector & lines) { std::vector failed; @@ -862,7 +856,7 @@ static std::string importTodoSh_2_0 (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importText (const std::vector & lines) +std::string CmdImport::text (const std::vector & lines) { std::vector failed; int count = 0; @@ -926,7 +920,7 @@ static std::string importText (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importCSV (const std::vector & lines) +std::string CmdImport::CSV (const std::vector & lines) { std::vector failed; @@ -1171,7 +1165,7 @@ static std::string importCSV (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -static std::string importYAML (const std::vector & lines) +std::string CmdImport::YAML (const std::vector & lines) { int count = 0; @@ -1285,7 +1279,7 @@ static std::string importYAML (const std::vector & lines) } //////////////////////////////////////////////////////////////////////////////// -int handleImport (std::string& outs) +int CmdImport::execute (const std::string&, std::string& output) { int rc = 0; std::stringstream out; @@ -1331,15 +1325,15 @@ int handleImport (std::string& outs) std::string identifier; switch (type) { - case task_1_4_3: identifier = "This looks like an older taskwarrior export file."; break; - case task_1_5_0: identifier = "This looks like a recent taskwarrior export file."; break; - case task_1_6_0: identifier = "This looks like a current taskwarrior export file."; break; - case task_cmd_line: identifier = "This looks like taskwarrior command line arguments."; break; - case todo_sh_2_0: identifier = "This looks like a todo.sh 2.x file."; break; - case csv: identifier = "This looks like a CSV file, but not a taskwarrior export file."; break; - case yaml: identifier = "This looks like a YAML file."; break; - case text: identifier = "This looks like a text file with one task per line."; break; - case not_a_clue: + case type_task_1_4_3: identifier = "This looks like an older taskwarrior export file."; break; + case type_task_1_5_0: identifier = "This looks like a recent taskwarrior export file."; break; + case type_task_1_6_0: identifier = "This looks like a current taskwarrior export file."; break; + case type_task_cmd_line: identifier = "This looks like taskwarrior command line arguments."; break; + case type_todo_sh_2_0: identifier = "This looks like a todo.sh 2.x file."; break; + case type_csv: identifier = "This looks like a CSV file, but not a taskwarrior export file."; break; + case type_yaml: identifier = "This looks like a YAML file."; break; + case type_text: identifier = "This looks like a text file with one task per line."; break; + case type_not_a_clue: throw std::string ("Taskwarrior cannot determine which type of file " "this is, and cannot proceed."); } @@ -1352,15 +1346,15 @@ int handleImport (std::string& outs) // Determine which type it might be, then attempt an import. switch (type) { - case task_1_4_3: out << importTask_1_4_3 (lines); break; - case task_1_5_0: out << importTask_1_5_0 (lines); break; - case task_1_6_0: out << importTask_1_6_0 (lines); break; - case task_cmd_line: out << importTaskCmdLine (lines); break; - case todo_sh_2_0: out << importTodoSh_2_0 (lines); break; - case csv: out << importCSV (lines); break; - case yaml: out << importYAML (lines); break; - case text: out << importText (lines); break; - case not_a_clue: /* to stop the compiler from complaining. */ break; + case type_task_1_4_3: out << task_1_4_3 (lines); break; + case type_task_1_5_0: out << task_1_5_0 (lines); break; + case type_task_1_6_0: out << task_1_6_0 (lines); break; + case type_task_cmd_line: out << taskCmdLine (lines); break; + case type_todo_sh_2_0: out << todoSh_2_0 (lines); break; + case type_csv: out << CSV (lines); break; + case type_yaml: out << YAML (lines); break; + case type_text: out << text (lines); break; + case type_not_a_clue: /* to stop the compiler from complaining. */ break; } if (tmpfile != "") @@ -1369,7 +1363,7 @@ int handleImport (std::string& outs) else throw std::string ("You must specify a file to import."); - outs = out.str (); + output = out.str (); return rc; } diff --git a/src/commands/CmdImport.h b/src/commands/CmdImport.h new file mode 100644 index 000000000..bb426ebd7 --- /dev/null +++ b/src/commands/CmdImport.h @@ -0,0 +1,67 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_CMDIMPORT +#define INCLUDED_CMDIMPORT +#define L10N // Localization complete. + +#include +#include + +class CmdImport : public Command +{ +public: + CmdImport (); + int execute (const std::string&, std::string&); + +private: + enum fileType + { + type_not_a_clue, + type_task_1_4_3, + type_task_1_5_0, + type_task_1_6_0, + type_task_cmd_line, + type_todo_sh_2_0, + type_csv, + type_yaml, + type_text + }; + + fileType determineFileType (const std::vector &); + void decorateTask (Task&); + std::string task_1_4_3 (const std::vector &); + std::string task_1_5_0 (const std::vector &); + std::string task_1_6_0 (const std::vector &); + std::string taskCmdLine (const std::vector &); + std::string todoSh_2_0 (const std::vector &); + std::string text (const std::vector &); + std::string CSV (const std::vector &); + std::string YAML (const std::vector &); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 229ec1b8d..c8f40d5f1 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ void Command::factory (std::map & all) c = new CmdHistoryMonthly (); all[c->keyword ()] = c; c = new CmdHistoryAnnual (); all[c->keyword ()] = c; c = new CmdIDs (); all[c->keyword ()] = c; + c = new CmdImport (); all[c->keyword ()] = c; c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdLog (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index c0851a1c1..bda08d050 100644 --- a/src/main.h +++ b/src/main.h @@ -84,9 +84,6 @@ std::string colorizeHeader (const std::string&); std::string colorizeFootnote (const std::string&); std::string colorizeDebug (const std::string&); -// import.cpp -int handleImport (std::string&); - // dependency.cpp bool dependencyIsBlocked (const Task&); void dependencyGetBlocked (const Task&, std::vector &);