diff --git a/ChangeLog b/ChangeLog index 4ac14efdf..08992f704 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ the description "Pay the bill", then "description.word:the" will match, but "description.word:th" will not. For partial word matches, there is still "description.contains:th". + + The 'version' command now complains about use of deprecated color names and + duplicate entries. + Fixed bug that showed a calendar for the year 2037 when 'task calendar due' was run, and there are no tasks with due dates. + Fixed bug #316 which caused the timesheet report to display an oddly sorted diff --git a/src/Config.cpp b/src/Config.cpp index 7b0657bcb..1ee2a1f86 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -83,6 +83,7 @@ bool Config::load (const std::string& file) std::string key = trim (line.substr (0, equal), " \t"); // no i18n std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n (*this)[key] = value; + sequence.push_back (key); } } } @@ -329,6 +330,13 @@ void Config::setDefaults () set ("alias.rm", "delete"); // TODO i18n } +//////////////////////////////////////////////////////////////////////////////// +void Config::clear () +{ + std::map ::clear (); + sequence.clear (); +} + //////////////////////////////////////////////////////////////////////////////// // Return the configuration value given the specified key. const std::string Config::get (const char* key) @@ -437,3 +445,71 @@ void Config::all (std::vector& items) } //////////////////////////////////////////////////////////////////////////////// +void Config::getSequence (std::vector& items) +{ + items = sequence; +} + +//////////////////////////////////////////////////////////////////////////////// +std::string Config::checkForDuplicates () +{ + std::vector duplicates; + std::map unique; + + foreach (i, sequence) + { + if (unique.find (*i) != unique.end ()) + duplicates.push_back (*i); + else + unique[*i] = 0; + } + + std::stringstream out; + if (duplicates.size ()) + { + out << "Found duplicate entries for:" << std::endl; + + foreach (i, duplicates) + out << " " << *i << std::endl; + + out << std::endl; + } + + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string Config::checkForDeprecatedColor () +{ + int count = 0; + std::vector deprecated; + foreach (i, *this) + { + if (i->first.find ("color.") != std::string::npos) + { + std::string value = get (i->first); + if (value.find ("_") != std::string::npos) + { + ++count; + deprecated.push_back (i->first); + } + } + } + + std::stringstream out; + if (count) + { + out << "Your .taskrc file contains color settings that use deprecated " + << "underscores. Please check:" + << std::endl; + + foreach (i, deprecated) + out << " " << *i << "=" << get (*i) << std::endl; + + out << std::endl; + } + + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Config.h b/src/Config.h index 9490b9dd3..8eda3fbb3 100644 --- a/src/Config.h +++ b/src/Config.h @@ -44,6 +44,7 @@ public: void createDefaultRC (const std::string&, const std::string&); void createDefaultData (const std::string&); void setDefaults (); + void clear (); const std::string get (const char*); const std::string get (const char*, const char*); @@ -56,6 +57,13 @@ public: void set (const std::string&, const double); void set (const std::string&, const std::string&); void all (std::vector &); + void getSequence (std::vector&); + + std::string checkForDuplicates (); + std::string checkForDeprecatedColor (); + +private: + std::vector sequence; }; #endif diff --git a/src/command.cpp b/src/command.cpp index 6066ef4c1..4c10d0b68 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -551,31 +551,8 @@ int handleVersion (std::string &outs) out << std::endl; } - // Complain about colors that still use underscores. - int countDeprecatedColors = 0; - std::vector deprecatedColors; - foreach (i, all) - { - if (i->find ("color.") != std::string::npos) - { - std::string value = context.config.get (*i); - if (value.find ("_") != std::string::npos) - { - ++countDeprecatedColors; - deprecatedColors.push_back (*i); - } - } - } - - if (countDeprecatedColors) - { - out << "Your .taskrc file contains color settings that use deprecated " - << "underscores. Please check:" - << std::endl; - - foreach (i, deprecatedColors) - out << " " << *i << "=" << context.config.get (*i) << std::endl; - } + out << context.config.checkForDeprecatedColor (); + out << context.config.checkForDuplicates (); // Verify installation. This is mentioned in the documentation as the way to // ensure everything is properly installed. diff --git a/src/tests/color.deprecated.t b/src/tests/color.deprecated.t new file mode 100755 index 000000000..fde69dde8 --- /dev/null +++ b/src/tests/color.deprecated.t @@ -0,0 +1,59 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, 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 => 6; + +# Create the rc file. +if (open my $fh, '>', 'color.rc') +{ + print $fh "data.location=.\n", + "color.pri.H=red on black\n", + "color.pri.M=red on_black\n"; + close $fh; + ok (-r 'color.rc', 'Created color.rc'); +} + +# Test the add command. +my $output = qx{../task rc:color.rc rc.longversion:off version}; +like ($output, qr/color\.pri\.M/ms, 'Deprecated color detected'); +unlike ($output, qr/color\.pri\.H/ms, 'Non-deprecated color ignored'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'color.rc'; +ok (!-r 'color.rc', 'Removed color.rc'); + +exit 0; + diff --git a/src/tests/config.duplicate.t b/src/tests/config.duplicate.t new file mode 100755 index 000000000..7ac8babd5 --- /dev/null +++ b/src/tests/config.duplicate.t @@ -0,0 +1,59 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, 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 => 6; + +# Create the rc file. +if (open my $fh, '>', 'duplicate.rc') +{ + print $fh "data.location=.\n", + "data.location=.\n", + "color=off\n"; + close $fh; + ok (-r 'duplicate.rc', 'Created duplicate.rc'); +} + +# Test the add command. +my $output = qx{../task rc:duplicate.rc rc.longversion:off version}; +like ($output, qr/data\.location/ms, 'Duplicate entry detected'); +unlike ($output, qr/colorl/ms, 'Single entry not ignored'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'duplicate.rc'; +ok (!-r 'duplicate.rc', 'Removed duplicate.rc'); + +exit 0; +