From 879f0fed784bb0fac952d6e0826653edd633e882 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 24 Dec 2010 00:28:06 -0500 Subject: [PATCH] Feature #574 - Added feature #574, default due dates (thanks to Erlan Sergaziev). --- AUTHORS | 1 + ChangeLog | 1 + NEWS | 2 ++ doc/man/taskrc.5 | 7 +++++++ src/Config.cpp | 1 + src/command.cpp | 20 +++++++++++++++++++- src/import.cpp | 7 +++++++ src/tests/default.t | 11 ++++++++--- 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 399c59e04..391037714 100644 --- a/AUTHORS +++ b/AUTHORS @@ -69,4 +69,5 @@ suggestions: Max Muller Sander Marechal Thomas Sattler + Erlan Sergaziev diff --git a/ChangeLog b/ChangeLog index a93c713cb..d5d5a90d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ intended to help scripts that manipulate task output. + Added feature #567, which makes it possible to apply an offset to the first month to be displayed in the calendar report (thanks to Michelle Crane). + + Added feature #574, default due dates (thanks to Erlan Sergaziev). + Added feature #575, including Danish holidays (thanks to Irfan Siddiqui). + Eliminated dependency on ncurses. + Fixed bug #515, which displayed an incorrect message after duplicating a diff --git a/NEWS b/NEWS index 74936375e..576763890 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,8 @@ New configuration options in taskwarrior 1.9.4 eliminates problems with task ID numbers for script writers. - calendar.offset=off and calendar.offset.value=-1 to apply an offset value to change the effective first month in the calendar report. + - default.due can be specified, and adds a default due date to all added + and imported tasks that don't otherwise have a due date. Newly deprecated features in taskwarrior 1.9.4 diff --git a/doc/man/taskrc.5 b/doc/man/taskrc.5 index 4c379b0a4..21808ca94 100644 --- a/doc/man/taskrc.5 +++ b/doc/man/taskrc.5 @@ -833,6 +833,13 @@ Provides a default priority for the .I task add command, if you don't specify one. The default is blank. +.TP +.B +default.due=... +Provides a default due date for the +.I task add +command, if you don't specify one. The default is blank. + .TP .B default.command=list diff --git a/src/Config.cpp b/src/Config.cpp index 94e6ae101..662ce6d14 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -241,6 +241,7 @@ std::string Config::defaults = "\n" "#default.project=foo # Default project for 'add' command\n" "#default.priority=M # Default priority for 'add' command\n" + "#default.due=eom # Default due date for 'add' command\n" "default.command=list # When no arguments are specified\n" "\n" "_forcecolor=no # Forces color to be on, even for non TTY output\n" diff --git a/src/command.cpp b/src/command.cpp index 5e03cd235..cad16611d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -87,6 +87,15 @@ int handleAdd (std::string& outs) context.task.set ("priority", defaultPriority); } + // Override with default.due, if not specified. + if (context.task.get ("due") == "") + { + std::string defaultDue = context.config.get ("default.due"); + if (defaultDue != "" && + Att::validNameValue ("due", "", defaultDue)) + context.task.set ("due", defaultDue); + } + // Include tags. foreach (tag, context.tagAdditions) context.task.addTag (*tag); @@ -181,6 +190,15 @@ int handleLog (std::string& outs) context.task.set ("priority", defaultPriority); } + // Override with default.due, if not specified. + if (context.task.get ("due") == "") + { + std::string defaultDue = context.config.get ("default.due"); + if (defaultDue != "" && + Att::validNameValue ("due", "", defaultDue)) + context.task.set ("due", defaultDue); + } + // Include tags. foreach (tag, context.tagAdditions) context.task.addTag (*tag); @@ -890,7 +908,7 @@ int handleShow (std::string& outs) "color.sync.added color.sync.changed color.sync.rejected " "color.undo.after confirmation curses data.location dateformat " "dateformat.holiday dateformat.report dateformat.annotation debug " - "default.command default.priority default.project defaultwidth due " + "default.command default.due default.priority default.project defaultwidth due " "dependency.confirmation dependency.reminder locale displayweeknumber " "export.ical.class echo.command fontunderline gc locking monthsperline " "nag next journal.time journal.time.start.annotation journal.info " diff --git a/src/import.cpp b/src/import.cpp index c26c55977..6acfd5e36 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -192,6 +192,13 @@ static void decorateTask (Task& task) defaultPriority != "" && Att::validNameValue ("priority", "", defaultPriority)) task.set ("priority", defaultPriority); + + // Override with default.due, if not specified. + std::string defaultDue = context.config.get ("default.due"); + if (!task.has ("due") && + defaultDue != "" && + Att::validNameValue ("due", "", defaultDue)) + task.set ("due", defaultDue); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/tests/default.t b/src/tests/default.t index 19f4ab0e4..b6c09785e 100755 --- a/src/tests/default.t +++ b/src/tests/default.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 18; +use Test::More tests => 22; # Create the rc file. if (open my $fh, '>', 'default.rc') @@ -36,7 +36,8 @@ if (open my $fh, '>', 'default.rc') print $fh "data.location=.\n", "default.command=list\n", "default.project=PROJECT\n", - "default.priority=M\n"; + "default.priority=M\n", + "default.due=eom\n"; close $fh; ok (-r 'default.rc', 'Created default.rc'); } @@ -47,13 +48,15 @@ my $output = qx{../task rc:default.rc list}; like ($output, qr/ all defaults/, 'task added'); like ($output, qr/ PROJECT /, 'default project added'); like ($output, qr/ M /, 'default priority added'); +like ($output, qr/\//, 'default due added'); unlink 'pending.data'; -qx{../task rc:default.rc add project:specific priority:L all specified}; +qx{../task rc:default.rc add project:specific priority:L due:eoy all specified}; $output = qx{../task rc:default.rc list}; like ($output, qr/ all specified/, 'task added'); like ($output, qr/ specific /, 'project specified'); like ($output, qr/ L /, 'priority specified'); +like ($output, qr/\//, 'due specified'); unlink 'pending.data'; qx{../task rc:default.rc add project:specific project specified}; @@ -61,6 +64,7 @@ $output = qx{../task rc:default.rc list}; like ($output, qr/ project specified/, 'task added'); like ($output, qr/ specific /, 'project specified'); like ($output, qr/ M /, 'default priority added'); +like ($output, qr/\//, 'default due added'); unlink 'pending.data'; qx{../task rc:default.rc add priority:L priority specified}; @@ -68,6 +72,7 @@ $output = qx{../task rc:default.rc list}; like ($output, qr/ priority specified/, 'task added'); like ($output, qr/ PROJECT /, 'default project added'); like ($output, qr/ L /, 'priority specified'); +like ($output, qr/\//, 'default due added'); $output = qx{../task rc:default.rc}; like ($output, qr/1 PROJECT L .+ priority specified/, 'default command worked');