mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Hooks
- Added more format hooks.
This commit is contained in:
parent
fa37e002f0
commit
ed7c3fad57
7 changed files with 511 additions and 3 deletions
|
@ -224,9 +224,14 @@ int runCustomReport (
|
|||
table.setColumnWidth (columnCount, Table::minimum);
|
||||
table.setColumnJustification (columnCount, Table::left);
|
||||
|
||||
std::string value;
|
||||
int row = 0;
|
||||
foreach (task, tasks)
|
||||
table.addCell (row++, columnCount, task->get ("project"));
|
||||
{
|
||||
value = task->get ("project");
|
||||
context.hooks.trigger ("format-project", "project", value);
|
||||
table.addCell (row++, columnCount, value);
|
||||
}
|
||||
}
|
||||
|
||||
else if (*col == "priority")
|
||||
|
@ -417,6 +422,7 @@ int runCustomReport (
|
|||
{
|
||||
Date dt (::atoi (created.c_str ()));
|
||||
age = formatSeconds ((time_t) (now - dt));
|
||||
context.hooks.trigger ("format-age", "age", age);
|
||||
table.addCell (row, columnCount, age);
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +444,7 @@ int runCustomReport (
|
|||
{
|
||||
Date dt (::atoi (created.c_str ()));
|
||||
age = formatSecondsCompact ((time_t) (now - dt));
|
||||
context.hooks.trigger ("format-age_compact", "age_compact", age);
|
||||
table.addCell (row, columnCount, age);
|
||||
}
|
||||
}
|
||||
|
@ -467,6 +474,7 @@ int runCustomReport (
|
|||
{
|
||||
task->getTags (all);
|
||||
join (tags, " ", all);
|
||||
context.hooks.trigger ("format-tags", "tags", tags);
|
||||
table.addCell (row++, columnCount, tags);
|
||||
}
|
||||
}
|
||||
|
@ -477,9 +485,14 @@ int runCustomReport (
|
|||
table.setColumnWidth (columnCount, Table::flexible);
|
||||
table.setColumnJustification (columnCount, Table::left);
|
||||
|
||||
std::string desc;
|
||||
int row = 0;
|
||||
foreach (task, tasks)
|
||||
table.addCell (row++, columnCount, task->get ("description"));
|
||||
{
|
||||
desc = task->get ("description");
|
||||
context.hooks.trigger ("format-description_only", "description_only", desc);
|
||||
table.addCell (row++, columnCount, desc);
|
||||
}
|
||||
}
|
||||
|
||||
else if (*col == "description")
|
||||
|
@ -488,9 +501,14 @@ int runCustomReport (
|
|||
table.setColumnWidth (columnCount, Table::flexible);
|
||||
table.setColumnJustification (columnCount, Table::left);
|
||||
|
||||
std::string desc;
|
||||
int row = 0;
|
||||
foreach (task, tasks)
|
||||
table.addCell (row++, columnCount, getFullDescription (*task, report));
|
||||
{
|
||||
desc = getFullDescription (*task, report);
|
||||
context.hooks.trigger ("format-description", "description", desc);
|
||||
table.addCell (row++, columnCount, desc);
|
||||
}
|
||||
}
|
||||
|
||||
else if (*col == "recur")
|
||||
|
|
82
src/tests/hook.format-age.t
Executable file
82
src/tests/hook.format-age.t
Executable file
|
@ -0,0 +1,82 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-age=" . $ENV{'PWD'} . "/hook:age\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function age (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo};
|
||||
sleep 1;
|
||||
$output = qx{../task rc:hook.rc list};
|
||||
|
||||
like ($output, qr/<\d\ssec>/, 'format-age hook age -> <age>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-age hook age -> <age> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
83
src/tests/hook.format-age_compact.t
Executable file
83
src/tests/hook.format-age_compact.t
Executable file
|
@ -0,0 +1,83 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-age_compact=" . $ENV{'PWD'} . "/hook:age\n",
|
||||
"report.list.columns=id,project,priority,due,active,age_compact,description\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function age (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo};
|
||||
sleep 1;
|
||||
$output = qx{../task rc:hook.rc list};
|
||||
|
||||
like ($output, qr/<\ds>/, 'format-age_compact hook age -> <age>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-age_compact hook age -> <age> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
81
src/tests/hook.format-description.t
Executable file
81
src/tests/hook.format-description.t
Executable file
|
@ -0,0 +1,81 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-description=" . $ENV{'PWD'} . "/hook:description\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function description (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo};
|
||||
$output = qx{../task rc:hook.rc ls};
|
||||
|
||||
like ($output, qr/<foo>/, 'format-description hook foo -> <foo>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-description hook foo -> <foo> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
82
src/tests/hook.format-description_only.t
Executable file
82
src/tests/hook.format-description_only.t
Executable file
|
@ -0,0 +1,82 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-description_only=" . $ENV{'PWD'} . "/hook:description_only\n",
|
||||
"report.ls.columns=id,project,priority,description_only\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function description_only (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo};
|
||||
$output = qx{../task rc:hook.rc ls};
|
||||
|
||||
like ($output, qr/<foo>/, 'format-description_only hook foo -> <foo>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-description_only hook foo -> <foo> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
81
src/tests/hook.format-project.t
Executable file
81
src/tests/hook.format-project.t
Executable file
|
@ -0,0 +1,81 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-project=" . $ENV{'PWD'} . "/hook:project\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function project (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo project:bar};
|
||||
$output = qx{../task rc:hook.rc list};
|
||||
|
||||
like ($output, qr/<bar>/, 'format-project hook project -> <project>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-project hook project -> <project> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
81
src/tests/hook.format-tags.t
Executable file
81
src/tests/hook.format-tags.t
Executable file
|
@ -0,0 +1,81 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2010, Paul Beckingham.
|
||||
## 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
|
||||
##
|
||||
################################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'hook.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"hooks=on\n",
|
||||
"hook.format-tags=" . $ENV{'PWD'} . "/hook:tags\n";
|
||||
close $fh;
|
||||
ok (-r 'hook.rc', 'Created hook.rc');
|
||||
}
|
||||
|
||||
# Create the hook functions.
|
||||
if (open my $fh, '>', 'hook')
|
||||
{
|
||||
print $fh "function tags (name, value)\n",
|
||||
" value = '<' .. value .. '>'\n",
|
||||
" return value, 0, nil\n",
|
||||
"end\n";
|
||||
close $fh;
|
||||
ok (-r 'hook', 'Created hook');
|
||||
}
|
||||
|
||||
my $output = qx{../task rc:hook.rc version};
|
||||
if ($output =~ /PUC-Rio/)
|
||||
{
|
||||
qx{../task rc:hook.rc add foo +t1 +t2};
|
||||
$output = qx{../task rc:hook.rc long};
|
||||
|
||||
like ($output, qr/<t1 t2>/, 'format-tags hook t1 t2 -> <t1 t2>');
|
||||
}
|
||||
else
|
||||
{
|
||||
pass ('format-tags hook t1 t2 -> <t1 t2> - skip: no Lua support');
|
||||
}
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'hook';
|
||||
ok (!-r 'hook', 'Removed hook');
|
||||
|
||||
unlink 'hook.rc';
|
||||
ok (!-r 'hook.rc', 'Removed hook.rc');
|
||||
|
||||
exit 0;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue