Enhancement - added echo of id, description

- Added an echo of the ID and description of the task for the start,
  stop, do, undo, delete and undelete commands.  Thanks to Bruce
  Dillahunty.
- Updated documentation.
- Added "echo.command=no" to delete.t, undo.t because the default
  value is "yes", which breaks tests.
- Fixed syntax errors in utf8.t
- Corrected expected number of tests in recur.t
This commit is contained in:
Paul Beckingham
2009-03-22 23:34:17 -04:00
parent ca933d7f39
commit f790df24c5
9 changed files with 69 additions and 16 deletions

View File

@@ -140,6 +140,7 @@ void Config::createDefault (const std::string& home)
{
fprintf (out, "data.location=%s\n", dataDir.c_str ());
fprintf (out, "confirmation=yes\n");
fprintf (out, "echo.command=yes\n");
fprintf (out, "next=2\n");
fprintf (out, "dateformat=m/d/Y\n");
fprintf (out, "#monthsperline=2\n");

View File

@@ -432,6 +432,8 @@ std::string handleVersion (Config& conf)
////////////////////////////////////////////////////////////////////////////////
std::string handleDelete (TDB& tdb, T& task, Config& conf)
{
std::stringstream out;
if (conf.get ("confirmation") != "yes" || confirm ("Permanently delete task?"))
{
std::vector <T> all;
@@ -450,11 +452,19 @@ std::string handleDelete (TDB& tdb, T& task, Config& conf)
// Scan all pending tasks for siblings of this task, and the parent
// itself, and delete them.
foreach (sibling, all)
{
if (sibling->getAttribute ("parent") == parent ||
sibling->getUUID () == parent)
{
tdb.deleteT (*sibling);
return std::string ("");
if (conf.get ("echo.command", true))
out << "Deleting recurring task "
<< sibling->getId ()
<< " "
<< sibling->getDescription ()
<< std::endl;
}
}
}
else
{
@@ -462,20 +472,32 @@ std::string handleDelete (TDB& tdb, T& task, Config& conf)
t->setStatus (T::deleted);
updateRecurrenceMask (tdb, all, *t);
tdb.deleteT (*t);
return std::string ("");
out << "Deleting recurring task "
<< t->getId ()
<< " "
<< t->getDescription ()
<< std::endl;
}
}
else
{
tdb.deleteT (*t);
if (conf.get ("echo.command", true))
out << "Deleting task "
<< t->getId ()
<< " "
<< t->getDescription ()
<< std::endl;
}
break; // No point continuing the loop.
}
}
}
else
return std::string ("Task not deleted.\n");
out << "Task not deleted." << std::endl;
return std::string ("");
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
@@ -490,6 +512,7 @@ std::string handleStart (TDB& tdb, T& task, Config& conf)
if (it->getId () == task.getId ())
{
T original (*it);
std::stringstream out;
if (original.getAttribute ("start") == "")
{
@@ -500,15 +523,20 @@ std::string handleStart (TDB& tdb, T& task, Config& conf)
original.setId (task.getId ());
tdb.modifyT (original);
if (conf.get ("echo.command", true))
out << "Started "
<< original.getId ()
<< " "
<< original.getDescription ()
<< std::endl;
nag (tdb, task, conf);
return std::string ("");
}
else
{
std::stringstream out;
out << "Task " << task.getId () << " already started." << std::endl;
return out.str ();
}
return out.str ();
}
}
@@ -528,6 +556,7 @@ std::string handleStop (TDB& tdb, T& task, Config& conf)
if (it->getId () == task.getId ())
{
T original (*it);
std::stringstream out;
if (original.getAttribute ("start") != "")
{
@@ -535,14 +564,15 @@ std::string handleStop (TDB& tdb, T& task, Config& conf)
original.setId (task.getId ());
tdb.modifyT (original);
return std::string ("");
if (conf.get ("echo.command", true))
out << "Stopped " << original.getId () << " " << original.getDescription () << std::endl;
}
else
{
std::stringstream out;
out << "Task " << task.getId () << " not started." << std::endl;
return out.str ();
}
return out.str ();
}
}
@@ -565,6 +595,13 @@ std::string handleDone (TDB& tdb, T& task, Config& conf)
{
if (t->getId () == task.getId ())
{
if (conf.get ("echo.command", true))
out << "Completed "
<< t->getId ()
<< " "
<< t->getDescription ()
<< std::endl;
t->setStatus (T::completed);
updateRecurrenceMask (tdb, all, *t);
break;

View File

@@ -33,7 +33,8 @@ use Test::More tests => 16;
# Create the rc file.
if (open my $fh, '>', 'undelete.rc')
{
print $fh "data.location=.\n";
print $fh "data.location=.\n",
"echo.command=no\n";
close $fh;
ok (-r 'undelete.rc', 'Created undelete.rc');
}

View File

@@ -28,7 +28,7 @@
use strict;
use warnings;
use Test::More tests => 6;
use Test::More tests => 5;
# Create the rc file.
if (open my $fh, '>', 'recur.rc')

View File

@@ -33,7 +33,8 @@ use Test::More tests => 15;
# Create the rc file.
if (open my $fh, '>', 'undo.rc')
{
print $fh "data.location=.\n";
print $fh "data.location=.\n",
"echo.command=no\n";
close $fh;
ok (-r 'undo.rc', 'Created undo.rc');
}

View File

@@ -62,11 +62,11 @@ diag ($output);
like ($output, qr/17/, 'all 17 tasks shown');
qx{../task rc:utf8.rc add project:Çirçös utf8 in project};
my $output = qx{../task rc:utf8.rc ls project:Çirçös};
$output = qx{../task rc:utf8.rc ls project:Çirçös};
like ($output, qr/Çirçös.+utf8 in project/, 'utf8 in project works');
qx{../task rc:utf8.rc add utf8 in tag +☺};
my $output = qx{../task rc:utf8.rc ls +☺};
$output = qx{../task rc:utf8.rc ls +☺};
like ($output, qr/utf8 in tag/, 'utf8 in tag works');
# Cleanup.