From df38d5aaa065f8d87a080a898ee56a7fd6732f4c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 10 Jun 2009 21:51:01 -0400 Subject: [PATCH] Code Cleanup - Relocated longUsage and shortUsage to report.cpp, where they belong, which has the positive side effect of allowing all the compiled unit tests to link. --- src/main.cpp | 236 --------------------------------------------- src/main.h | 4 +- src/report.cpp | 227 +++++++++++++++++++++++++++++++++++++++++++ src/tests/Makefile | 3 +- 4 files changed, 231 insertions(+), 239 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cbdec7a75..70760ad45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,242 +53,6 @@ // Global context for use by all. Context context; -//////////////////////////////////////////////////////////////////////////////// -std::string shortUsage () -{ - std::stringstream out; - Table table; - int width = context.config.get ("defaultwidth", (int) 80); -#ifdef HAVE_LIBNCURSES - if (context.config.get ("curses", true)) - { - WINDOW* w = initscr (); - width = w->_maxx + 1; - endwin (); - } -#endif - - table.addColumn (" "); - table.addColumn (" "); - table.addColumn (" "); - - table.setColumnJustification (0, Table::left); - table.setColumnJustification (1, Table::left); - table.setColumnJustification (2, Table::left); - - table.setColumnWidth (0, Table::minimum); - table.setColumnWidth (1, Table::minimum); - table.setColumnWidth (2, Table::flexible); - table.setTableWidth (width); - table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); - - int row = table.addRow (); - table.addCell (row, 0, "Usage:"); - table.addCell (row, 1, "task"); - - row = table.addRow (); - table.addCell (row, 1, "task add [tags] [attrs] desc..."); - table.addCell (row, 2, "Adds a new task"); - - row = table.addRow (); - table.addCell (row, 1, "task append [tags] [attrs] desc..."); - table.addCell (row, 2, "Appends more description to an existing task"); - - row = table.addRow (); - table.addCell (row, 1, "task annotate ID desc..."); - table.addCell (row, 2, "Adds an annotation to an existing task"); - - row = table.addRow (); - table.addCell (row, 1, "task completed [tags] [attrs] desc..."); - table.addCell (row, 2, "Chronological listing of all completed tasks matching the specified criteria"); - - row = table.addRow (); - table.addCell (row, 1, "task ID [tags] [attrs] [desc...]"); - table.addCell (row, 2, "Modifies the existing task with provided arguments"); - - row = table.addRow (); - table.addCell (row, 1, "task ID /from/to/"); - table.addCell (row, 2, "Performs one substitution on the task description, for fixing mistakes"); - - row = table.addRow (); - table.addCell (row, 1, "task ID /from/to/g"); - table.addCell (row, 2, "Performs all substitutions on the task description, for fixing mistakes"); - - row = table.addRow (); - table.addCell (row, 1, "task edit ID"); - table.addCell (row, 2, "Launches an editor to let you modify all aspects of a task directly, therefore it is to be used carefully"); - - row = table.addRow (); - table.addCell (row, 1, "task duplicate ID [tags] [attrs] [desc...]"); - table.addCell (row, 2, "Duplicates the specified task, and allows modifications"); - - row = table.addRow (); - table.addCell (row, 1, "task delete ID"); - table.addCell (row, 2, "Deletes the specified task"); - - row = table.addRow (); - table.addCell (row, 1, "task undelete ID"); - table.addCell (row, 2, "Undeletes the specified task, provided a report has not yet been run"); - - row = table.addRow (); - table.addCell (row, 1, "task info ID"); - table.addCell (row, 2, "Shows all data, metadata for specified task"); - - row = table.addRow (); - table.addCell (row, 1, "task start ID"); - table.addCell (row, 2, "Marks specified task as started"); - - row = table.addRow (); - table.addCell (row, 1, "task stop ID"); - table.addCell (row, 2, "Removes the 'start' time from a task"); - - row = table.addRow (); - table.addCell (row, 1, "task done ID [tags] [attrs] [desc...]"); - table.addCell (row, 2, "Marks the specified task as completed"); - - row = table.addRow (); - table.addCell (row, 1, "task undo ID"); - table.addCell (row, 2, "Marks the specified done task as pending, provided a report has not yet been run"); - - row = table.addRow (); - table.addCell (row, 1, "task projects"); - table.addCell (row, 2, "Shows a list of all project names used, and how many tasks are in each"); - - row = table.addRow (); - table.addCell (row, 1, "task tags"); - table.addCell (row, 2, "Shows a list of all tags used"); - - row = table.addRow (); - table.addCell (row, 1, "task summary"); - table.addCell (row, 2, "Shows a report of task status by project"); - - row = table.addRow (); - table.addCell (row, 1, "task timesheet [weeks]"); - table.addCell (row, 2, "Shows a weekly report of tasks completed and started"); - - row = table.addRow (); - table.addCell (row, 1, "task history"); - table.addCell (row, 2, "Shows a report of task history, by month"); - - row = table.addRow (); - table.addCell (row, 1, "task ghistory"); - table.addCell (row, 2, "Shows a graphical report of task history, by month"); - - row = table.addRow (); - table.addCell (row, 1, "task next"); - table.addCell (row, 2, "Shows the most important tasks for each project"); - - row = table.addRow (); - table.addCell (row, 1, "task calendar"); - table.addCell (row, 2, "Shows a monthly calendar, with due tasks marked"); - - row = table.addRow (); - table.addCell (row, 1, "task active"); - table.addCell (row, 2, "Shows all task that are started, but not completed"); - - row = table.addRow (); - table.addCell (row, 1, "task overdue"); - table.addCell (row, 2, "Shows all incomplete tasks that are beyond their due date"); - - row = table.addRow (); - table.addCell (row, 1, "task stats"); - table.addCell (row, 2, "Shows task database statistics"); - - row = table.addRow (); - table.addCell (row, 1, "task import"); - table.addCell (row, 2, "Imports tasks from a variety of formats"); - - row = table.addRow (); - table.addCell (row, 1, "task export"); - table.addCell (row, 2, "Exports all tasks as a CSV file"); - - row = table.addRow (); - table.addCell (row, 1, "task color"); - table.addCell (row, 2, "Displays all possible colors"); - - row = table.addRow (); - table.addCell (row, 1, "task version"); - table.addCell (row, 2, "Shows the task version number"); - - row = table.addRow (); - table.addCell (row, 1, "task help"); - table.addCell (row, 2, "Shows the long usage text"); - - // Add custom reports here... - std::vector all; - allCustomReports (all); - foreach (report, all) - { - std::string command = std::string ("task ") + *report + std::string (" [tags] [attrs] desc..."); - std::string description = context.config.get ( - std::string ("report.") + *report + ".description", std::string ("(missing description)")); - - row = table.addRow (); - table.addCell (row, 1, command); - table.addCell (row, 2, description); - } - - out << table.render () - << std::endl - << "See http://taskwarrior.org/wiki/taskwarrior/Download for the latest " - << "releases and a full tutorial. New releases containing fixes and " - << "enhancements are made frequently. Join in the discussion of task, " - << "present and future, at http://taskwarrior.org" - << std::endl - << std::endl; - - return out.str (); -} - -//////////////////////////////////////////////////////////////////////////////// -std::string longUsage () -{ - std::stringstream out; - out << shortUsage () - << "ID is the numeric identifier displayed by the 'task list' command. " - << "You can specify multiple IDs for task commands, and multiple tasks " - << "will be affected. To specify multiple IDs make sure you use one " - << "of these forms:" << "\n" - << " task delete 1,2,3" << "\n" - << " task info 1-3" << "\n" - << " task pri:H 1,2-5,19" << "\n" - << "\n" - << "Tags are arbitrary words, any quantity:" << "\n" - << " +tag The + means add the tag" << "\n" - << " -tag The - means remove the tag" << "\n" - << "\n" - << "Attributes are:" << "\n" - << " project: Project name" << "\n" - << " priority: Priority" << "\n" - << " due: Due date" << "\n" - << " recur: Recurrence frequency" << "\n" - << " until: Recurrence end date" << "\n" - << " fg: Foreground color" << "\n" - << " bg: Background color" << "\n" - << "\n" - << "The default .taskrc file can be overridden with:" << "\n" - << " task rc: ..." << "\n" - << "\n" - << "The values in .taskrc (or alternate) can be overridden with:" << "\n" - << " task ... rc.:" << "\n" - << "\n" - << "Any command or attribute name may be abbreviated if still unique:" << "\n" - << " task list project:Home" << "\n" - << " task li pro:Home" << "\n" - << "\n" - << "Some task descriptions need to be escaped because of the shell:" << "\n" - << " task add \"quoted ' quote\"" << "\n" - << " task add escaped \\' quote" << "\n" - << "\n" - << "The argument -- tells task to treat all other args as description." << "\n" - << "\n" - << "Many characters have special meaning to the shell, including:" << "\n" - << " $ ! ' \" ( ) ; \\ ` * ? { } [ ] < > | & % # ~" << "\n" - << std::endl; - - return out.str (); -} - //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { diff --git a/src/main.h b/src/main.h index 6714603e2..1efeaa283 100644 --- a/src/main.h +++ b/src/main.h @@ -53,8 +53,6 @@ void gatherNextTasks (const TDB&, T&, std::vector &, std::vector &); void onChangeCallback (); std::string runTaskCommand (int, char**, TDB&, bool gc = true, bool shadow = true); std::string runTaskCommand (std::vector &, TDB&, bool gc = false, bool shadow = false); -std::string shortUsage (); -std::string longUsage (); // recur.cpp void handleRecurrence (); @@ -91,6 +89,8 @@ int deltaSubstitutions (T&, T&); std::string handleEdit (); // report.cpp +std::string shortUsage (); +std::string longUsage (); void filterSequence (std::vector&, T&); void filter (std::vector&, T&); std::string handleInfo (); diff --git a/src/report.cpp b/src/report.cpp index b7bdf9944..6a0f8213f 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -50,6 +50,233 @@ extern Context context; +//////////////////////////////////////////////////////////////////////////////// +std::string shortUsage () +{ + std::stringstream out; + Table table; + + table.addColumn (" "); + table.addColumn (" "); + table.addColumn (" "); + + table.setColumnJustification (0, Table::left); + table.setColumnJustification (1, Table::left); + table.setColumnJustification (2, Table::left); + + table.setColumnWidth (0, Table::minimum); + table.setColumnWidth (1, Table::minimum); + table.setColumnWidth (2, Table::flexible); + table.setTableWidth (context.getWidth ()); + table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); + + int row = table.addRow (); + table.addCell (row, 0, "Usage:"); + table.addCell (row, 1, "task"); + + row = table.addRow (); + table.addCell (row, 1, "task add [tags] [attrs] desc..."); + table.addCell (row, 2, "Adds a new task"); + + row = table.addRow (); + table.addCell (row, 1, "task append [tags] [attrs] desc..."); + table.addCell (row, 2, "Appends more description to an existing task"); + + row = table.addRow (); + table.addCell (row, 1, "task annotate ID desc..."); + table.addCell (row, 2, "Adds an annotation to an existing task"); + + row = table.addRow (); + table.addCell (row, 1, "task completed [tags] [attrs] desc..."); + table.addCell (row, 2, "Chronological listing of all completed tasks matching the specified criteria"); + + row = table.addRow (); + table.addCell (row, 1, "task ID [tags] [attrs] [desc...]"); + table.addCell (row, 2, "Modifies the existing task with provided arguments"); + + row = table.addRow (); + table.addCell (row, 1, "task ID /from/to/"); + table.addCell (row, 2, "Performs one substitution on the task description, for fixing mistakes"); + + row = table.addRow (); + table.addCell (row, 1, "task ID /from/to/g"); + table.addCell (row, 2, "Performs all substitutions on the task description, for fixing mistakes"); + + row = table.addRow (); + table.addCell (row, 1, "task edit ID"); + table.addCell (row, 2, "Launches an editor to let you modify all aspects of a task directly, therefore it is to be used carefully"); + + row = table.addRow (); + table.addCell (row, 1, "task duplicate ID [tags] [attrs] [desc...]"); + table.addCell (row, 2, "Duplicates the specified task, and allows modifications"); + + row = table.addRow (); + table.addCell (row, 1, "task delete ID"); + table.addCell (row, 2, "Deletes the specified task"); + + row = table.addRow (); + table.addCell (row, 1, "task undelete ID"); + table.addCell (row, 2, "Undeletes the specified task, provided a report has not yet been run"); + + row = table.addRow (); + table.addCell (row, 1, "task info ID"); + table.addCell (row, 2, "Shows all data, metadata for specified task"); + + row = table.addRow (); + table.addCell (row, 1, "task start ID"); + table.addCell (row, 2, "Marks specified task as started"); + + row = table.addRow (); + table.addCell (row, 1, "task stop ID"); + table.addCell (row, 2, "Removes the 'start' time from a task"); + + row = table.addRow (); + table.addCell (row, 1, "task done ID [tags] [attrs] [desc...]"); + table.addCell (row, 2, "Marks the specified task as completed"); + + row = table.addRow (); + table.addCell (row, 1, "task undo ID"); + table.addCell (row, 2, "Marks the specified done task as pending, provided a report has not yet been run"); + + row = table.addRow (); + table.addCell (row, 1, "task projects"); + table.addCell (row, 2, "Shows a list of all project names used, and how many tasks are in each"); + + row = table.addRow (); + table.addCell (row, 1, "task tags"); + table.addCell (row, 2, "Shows a list of all tags used"); + + row = table.addRow (); + table.addCell (row, 1, "task summary"); + table.addCell (row, 2, "Shows a report of task status by project"); + + row = table.addRow (); + table.addCell (row, 1, "task timesheet [weeks]"); + table.addCell (row, 2, "Shows a weekly report of tasks completed and started"); + + row = table.addRow (); + table.addCell (row, 1, "task history"); + table.addCell (row, 2, "Shows a report of task history, by month"); + + row = table.addRow (); + table.addCell (row, 1, "task ghistory"); + table.addCell (row, 2, "Shows a graphical report of task history, by month"); + + row = table.addRow (); + table.addCell (row, 1, "task next"); + table.addCell (row, 2, "Shows the most important tasks for each project"); + + row = table.addRow (); + table.addCell (row, 1, "task calendar"); + table.addCell (row, 2, "Shows a monthly calendar, with due tasks marked"); + + row = table.addRow (); + table.addCell (row, 1, "task active"); + table.addCell (row, 2, "Shows all task that are started, but not completed"); + + row = table.addRow (); + table.addCell (row, 1, "task overdue"); + table.addCell (row, 2, "Shows all incomplete tasks that are beyond their due date"); + + row = table.addRow (); + table.addCell (row, 1, "task stats"); + table.addCell (row, 2, "Shows task database statistics"); + + row = table.addRow (); + table.addCell (row, 1, "task import"); + table.addCell (row, 2, "Imports tasks from a variety of formats"); + + row = table.addRow (); + table.addCell (row, 1, "task export"); + table.addCell (row, 2, "Exports all tasks as a CSV file"); + + row = table.addRow (); + table.addCell (row, 1, "task color"); + table.addCell (row, 2, "Displays all possible colors"); + + row = table.addRow (); + table.addCell (row, 1, "task version"); + table.addCell (row, 2, "Shows the task version number"); + + row = table.addRow (); + table.addCell (row, 1, "task help"); + table.addCell (row, 2, "Shows the long usage text"); + + // Add custom reports here... + std::vector all; + allCustomReports (all); + foreach (report, all) + { + std::string command = std::string ("task ") + *report + std::string (" [tags] [attrs] desc..."); + std::string description = context.config.get ( + std::string ("report.") + *report + ".description", std::string ("(missing description)")); + + row = table.addRow (); + table.addCell (row, 1, command); + table.addCell (row, 2, description); + } + + out << table.render () + << std::endl + << "See http://taskwarrior.org/wiki/taskwarrior/Download for the latest " + << "releases and a full tutorial. New releases containing fixes and " + << "enhancements are made frequently. Join in the discussion of task, " + << "present and future, at http://taskwarrior.org" + << std::endl + << std::endl; + + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string longUsage () +{ + std::stringstream out; + out << shortUsage () + << "ID is the numeric identifier displayed by the 'task list' command. " + << "You can specify multiple IDs for task commands, and multiple tasks " + << "will be affected. To specify multiple IDs make sure you use one " + << "of these forms:" << "\n" + << " task delete 1,2,3" << "\n" + << " task info 1-3" << "\n" + << " task pri:H 1,2-5,19" << "\n" + << "\n" + << "Tags are arbitrary words, any quantity:" << "\n" + << " +tag The + means add the tag" << "\n" + << " -tag The - means remove the tag" << "\n" + << "\n" + << "Attributes are:" << "\n" + << " project: Project name" << "\n" + << " priority: Priority" << "\n" + << " due: Due date" << "\n" + << " recur: Recurrence frequency" << "\n" + << " until: Recurrence end date" << "\n" + << " fg: Foreground color" << "\n" + << " bg: Background color" << "\n" + << "\n" + << "The default .taskrc file can be overridden with:" << "\n" + << " task rc: ..." << "\n" + << "\n" + << "The values in .taskrc (or alternate) can be overridden with:" << "\n" + << " task ... rc.:" << "\n" + << "\n" + << "Any command or attribute name may be abbreviated if still unique:" << "\n" + << " task list project:Home" << "\n" + << " task li pro:Home" << "\n" + << "\n" + << "Some task descriptions need to be escaped because of the shell:" << "\n" + << " task add \"quoted ' quote\"" << "\n" + << " task add escaped \\' quote" << "\n" + << "\n" + << "The argument -- tells task to treat all other args as description." << "\n" + << "\n" + << "Many characters have special meaning to the shell, including:" << "\n" + << " $ ! ' \" ( ) ; \\ ` * ? { } [ ] < > | & % # ~" << "\n" + << std::endl; + + return out.str (); +} + //////////////////////////////////////////////////////////////////////////////// // TODO Obsolete void filterSequence (std::vector& all, T& task) diff --git a/src/tests/Makefile b/src/tests/Makefile index d0c0cff92..090344daf 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -7,7 +7,8 @@ OBJECTS = ../TDB.o ../TDB2.o ../T.o ../Task.o ../parse.o ../text.o ../Date.o \ ../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o \ ../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \ ../Filter.o ../Context.o ../Keymap.o ../Cmd.o ../command.o \ - ../report.o ../Table.o ../Grid.o ../color.o ../rules.o ../recur.o + ../report.o ../Table.o ../Grid.o ../color.o ../rules.o ../recur.o \ + ../interactive.o all: $(PROJECT)