From 0faf7fa8ee5ef1bb2a2bc10afa4c9ce5b037c51e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 15 Jan 2010 02:50:46 -0500 Subject: [PATCH] Config - defaults - Config is now providing a default set of all configuration variables. - The default set is used to both initialize a Config object, and to create a sample .taskrc. --- ChangeLog | 4 +- src/Config.cpp | 597 ++++++++++++++++------------------- src/Config.h | 17 +- src/command.cpp | 1 - src/tests/add.t | 3 +- src/tests/annotate.t | 1 + src/tests/att.t.cpp | 4 +- src/tests/basic.t | 3 +- src/tests/config.duplicate.t | 59 ---- src/tests/delete.t | 1 + src/tests/sequence.t | 3 +- src/tests/shadow.t | 1 + 12 files changed, 298 insertions(+), 396 deletions(-) delete mode 100755 src/tests/config.duplicate.t diff --git a/ChangeLog b/ChangeLog index 741de875f..10f9b45c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,8 +24,8 @@ + Added new 'config' command to display the configuration settings of task. As a consequence 'version' now only shows the version number and legal information. - + The 'config' command now complains about use of deprecated color names and - duplicate entries in .taskrc. + + The 'config' command now complains about use of deprecated color names in + your .taskrc file. + Task now supports nested .taskrc files using the "include /path" directive. + The 'entry', 'start' and 'end' columns now have equivalents that include the time, and are called 'entry_time', 'start_time', and 'end_time', for use in diff --git a/src/Config.cpp b/src/Config.cpp index 486be85af..f75691251 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -27,31 +27,229 @@ #include #include #include +#include #include #include #include #include #include #include "Path.h" +#include "File.h" #include "Config.h" #include "text.h" #include "util.h" //////////////////////////////////////////////////////////////////////////////// -// These are default (but overridable) reports. These entries are necessary -// because these three reports were converted from hard-coded reports to custom -// reports, and therefore need these config file entries. However, users are -// already used to seeing these five reports, but do not have these entries. -// The choice was a) make users edit their .taskrc files, b) write a .taskrc -// upgrade program to make the change, or c) this. +// This string is used in two ways: +// 1) It is used to create a new .taskrc file, by copying it directly to disk. +// 2) It is parsed and used as default values for all Config.get calls. +std::string Config::defaults = + "# Task program configuration file.\n" + "# For more documentation, see http://taskwarrior.org or try 'man task' and 'man taskrc'\n" + "\n" + "# Files\n" + "data.location=~/.task\n" + "locking=on # Use file-level locking\n" + "\n" + "# Terminal\n" + "curses=on # Use ncurses library to determine terminal width\n" + "defaultwidth=80 # Without ncurses, assumed width\n" + "#editor=vi # Preferred text editor\n" + "\n" + "# Miscellaneous\n" + "confirmation=yes # Confirmation on delete, big changes\n" + "echo.command=yes # Details on command just run\n" + "annotation.details=2 # Level of verbosity for annotations in reports\n" + "next=2 # How many tasks per project in next report\n" + "bulk=2 # > 2 tasks considered 'a lot', for confirmation\n" + "nag=You have higher priority tasks. # Nag message to keep you honest\n" + "\n" + "# Dates\n" + "dateformat=m/d/Y # Preferred input and display date format\n" + "#reportdateformat=m/d/Y # Preferred input and display date format\n" + "weekstart=Sunday # Sunday or Monday only\n" + "displayweeknumber=yes # Show week numbers on calendar\n" + "due=7 # Task is considered due in 7 days\n" + "#calendar.details=yes # Calendar shows information for tasks w/due dates\n" + "#calendar.details.report=list # Report to use when showing task information in cal\n" + "#monthsperline=3 # Number of calendar months on a line\n" + "\n" + "# Color controls.\n" + "color=on # Enable color\n" + "color.overdue=bold red # Color of overdue tasks\n" + "color.due=bold yellow # Color of due tasks\n" + "color.pri.H=bold # Color of priority:H tasks\n" + "#color.pri.M=on yellow # Color of priority:M tasks\n" + "#color.pri.L=on green # Color of priority:L tasks\n" + "#color.pri.none=white on blue # Color of priority: tasks\n" + "color.active=bold cyan # Color of active tasks\n" + "color.tagged=yellow # Color of tagged tasks\n" + "#color.tag.bug=yellow # Color of +bug tasks\n" + "#color.project.garden=on green # Color of project:garden tasks\n" + "#color.keyword.car=on blue # Color of description.contains:car tasks\n" + "#color.recurring=on red # Color of recur.any: tasks\n" + "#color.header=bold green # Color of header messages\n" + "#color.footnote=bold green # Color of footnote messages\n" + "#color.alternate=on rgb253 # Alternate color for line coloring\n" + "color.calendar.today=black on cyan # Color of today in calendar\n" + "color.calendar.due=black on green # Color of days with due tasks in calendar\n" + "color.calendar.overdue=black on red # Color of days with overdue tasks in calendar\n" + "color.calendar.weekend=black on white # Color of weekend days in calendar\n" + "#color.debug=magenta # Color of diagnostic output\n" + "color.pri.H=bold # Color of priority:H tasks\n" + "color.history.add=on red # Color of added tasks in the history reports\n" + "color.history.delete=on yellow # Color of deleted tasks in the history reports\n" + "color.history.done=on green # Color of completed tasks in the history reports\n" + "\n" + "#shadow.file=/tmp/shadow.txt # Location of shadow file\n" + "#shadow.command=list # Task command for shadow file\n" + "#shadow.notify=on # Footnote when updated\n" + "\n" + "#default.project=foo # Default project for 'add' command\n" + "#default.priority=M # Default priority 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" + "blanklines=true # Use more whitespace in output\n" + "complete.all.projects=no # Include old project names in 'projects' command\n" + "complete.all.tags=no # Include old tag names in 'tags' command\n" + "debug=no # Display diagnostics\n" + "fontunderline=yes # Uses underlines rather than -------\n" + "shell.prompt=task> # Prompt used by the shell command\n" + "\n" + "# Import heuristics - alternate names for fields (comma-separated list of names)\n" + "#import.synonym.bg=?\n" + "#import.synonym.description=?\n" + "#import.synonym.due=?\n" + "#import.synonym.end=?\n" + "#import.synonym.entry=?\n" + "#import.synonym.fg=?\n" + "#import.synonym.id=?\n" + "#import.synonym.priority=?\n" + "#import.synonym.project=?\n" + "#import.synonym.recur=?\n" + "#import.synonym.start=?\n" + "#import.synonym.status=?\n" + "#import.synonym.tags=?\n" + "#import.synonym.uuid=?\n" + "\n" + "alias.rm=delete # Alias for the delete command\n" + "\n" + "# Fields: id,uuid,project,priority,priority_long,entry,entry_time,\n" + "# start,entry_time,due,recur,recurrence_indicator,age,\n" + "# age_compact,active,tags,tag_indicator,description,\n" + "# description_only,end,end_time\n" + "# Description: This report is ...\n" + "# Sort: due+,priority-,project+\n" + "# Filter: pro:x pri:H +bug limit:10\n" + "\n" + "# task long\n" + "report.long.description=Lists all task, all data, matching the specified criteria\n" + "report.long.columns=id,project,priority,entry,start,due,recur,age,tags,description\n" + "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n" + "report.long.sort=due+,priority-,project+\n" + "report.long.filter=status:pending\n" + "\n" + "# task list\n" + "report.list.description=Lists all tasks matching the specified criteria\n" + "report.list.columns=id,project,priority,due,active,age,description\n" + "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.list.sort=due+,priority-,project+\n" + "report.list.filter=status:pending\n" + "\n" + "# task ls\n" + "report.ls.description=Minimal listing of all tasks matching the specified criteria\n" + "report.ls.columns=id,project,priority,description\n" + "report.ls.labels=ID,Project,Pri,Description\n" + "report.ls.sort=priority-,project+\n" + "report.ls.filter=status:pending\n" + "\n" + "# task minimal\n" + "report.minimal.description=A really minimal listing\n" + "report.minimal.columns=id,project,description\n" + "report.minimal.labels=ID,Project,Description\n" + "report.minimal.sort=project+,description+\n" + "report.minimal.filter=status:pending\n" + "\n" + "# task newest\n" + "report.newest.description=Shows the newest tasks\n" + "report.newest.columns=id,project,priority,due,active,age,description\n" + "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.newest.sort=id-\n" + "report.newest.filter=status:pending limit:10\n" + "\n" + "# task oldest\n" + "report.oldest.description=Shows the oldest tasks\n" + "report.oldest.columns=id,project,priority,due,active,age,description\n" + "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.oldest.sort=id+\n" + "report.oldest.filter=status:pending limit:10\n" + "\n" + "# task overdue\n" + "report.overdue.description=Lists overdue tasks matching the specified criteria\n" + "report.overdue.columns=id,project,priority,due,active,age,description\n" + "report.overdue.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.overdue.sort=due+,priority-,project+\n" + "report.overdue.filter=status:pending due.before:today\n" + "\n" + "# task active\n" + "report.active.description=Lists active tasks matching the specified criteria\n" + "report.active.columns=id,project,priority,due,active,age,description\n" + "report.active.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.active.sort=due+,priority-,project+\n" + "report.active.filter=status:pending start.any:\n" + "\n" + "# task completed\n" + "report.completed.description=Lists completed tasks matching the specified criteria\n" + "report.completed.columns=end,project,priority,age,description\n" + "report.completed.labels=Complete,Project,Pri,Age,Description\n" + "report.completed.sort=end+,priority-,project+\n" + "report.completed.filter=status:completed\n" + "\n" + "# task recurring\n" + "report.recurring.description=Lists recurring tasks matching the specified criteria\n" + "report.recurring.columns=id,project,priority,due,recur,active,age,description\n" + "report.recurring.labels=ID,Project,Pri,Due,Recur,Active,Age,Description\n" + "report.recurring.sort=due+,priority-,project+\n" + "report.recurring.filter=status:pending parent.any:\n" + "\n" + "# task waiting\n" + "report.waiting.description=Lists all waiting tasks matching the specified criteria\n" + "report.waiting.columns=id,project,priority,wait,age,description\n" + "report.waiting.labels=ID,Project,Pri,Wait,Age,Description\n" + "report.waiting.sort=wait+,priority-,project+\n" + "report.waiting.filter=status:waiting\n" + "\n" + "# task all\n" + "report.all.description=Lists all tasks matching the specified criteria\n" + "report.all.columns=id,project,priority,due,active,age,description\n" + "report.all.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.all.sort=due+,priority-,project+\n" + "\n" + "# task next\n" + "report.next.description=Lists the most urgent tasks\n" + "report.next.columns=id,project,priority,due,active,age,description\n" + "report.next.labels=ID,Project,Pri,Due,Active,Age,Description\n" + "report.next.sort=due+,priority-,project+\n" + "report.next.filter=status:pending\n" + "\n"; + +//////////////////////////////////////////////////////////////////////////////// +// DO NOT CALL Config::setDefaults. +// +// This is a default constructor, and as such is only used to: +// a) initialize a default Context constructor +// b) run unit tests +// +// In all real use cases, Config::load is called. Config::Config () { - setDefaults (); } //////////////////////////////////////////////////////////////////////////////// Config::Config (const std::string& file) { + setDefaults (); load (file); } @@ -63,234 +261,94 @@ Config::Config (const std::string& file) // Nested files are now supported, with the following construct: // include /absolute/path/to/file // -bool Config::load (const std::string& file, int nest /* = 1 */) +void Config::load (const std::string& file, int nest /* = 1 */) { if (nest > 10) throw std::string ("Configuration file nested to more than 10 levels deep" " - this has to be a mistake."); - std::ifstream in; - in.open (file.c_str (), std::ifstream::in); - if (in.good ()) + // First time in, load the default values. + if (nest == 1) + setDefaults (); + + // Read the file, then parse the contents. + std::string contents; + if (File::read (file, contents) && contents.length ()) + parse (contents, nest); +} + +//////////////////////////////////////////////////////////////////////////////// +void Config::parse (const std::string& input, int nest /* = 1 */) +{ + // Shortcut case for default constructor. + if (input.length () == 0) + return; + + // Split the input into lines. + std::vector lines; + split (lines, input, "\n"); + + // Parse each line. + std::vector ::iterator it; + for (it = lines.begin (); it != lines.end (); ++it) { - std::string line; - while (getline (in, line)) + std::string line = *it; + + // Remove comments. + std::string::size_type pound = line.find ("#"); // no i18n + if (pound != std::string::npos) + line = line.substr (0, pound); + + line = trim (line, " \t"); // no i18n + + // Skip empty lines. + if (line.length () > 0) { - // Remove comments. - std::string::size_type pound = line.find ("#"); // no i18n - if (pound != std::string::npos) - line = line.substr (0, pound); - - line = trim (line, " \t"); // no i18n - - // Skip empty lines. - if (line.length () > 0) + std::string::size_type equal = line.find ("="); // no i18n + if (equal != std::string::npos) { - std::string::size_type equal = line.find ("="); // no i18n - if (equal != std::string::npos) - { - 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 + 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); - } - else + (*this)[key] = value; + } + else + { + std::string::size_type include = line.find ("include"); // no i18n. + if (include != std::string::npos) { - std::string::size_type include = line.find ("include"); // no i18n. - if (include != std::string::npos) + Path included (trim (line.substr (include + 7), " \t")); + if (included.is_absolute ()) { - Path included (trim (line.substr (include + 7), " \t")); - if (included.is_absolute ()) - { - if (included.readable ()) - this->load (included.data, nest + 1); - else - throw std::string ("Could not read include file '") + included.data + "'"; - } + if (included.readable ()) + this->load (included.data, nest + 1); else - throw std::string ("Can only include files with absolute paths, not '") + included.data + "'"; + throw std::string ("Could not read include file '") + included.data + "'"; } else - throw std::string ("Malformed entry in ") + file + ": '" + line + "'"; + throw std::string ("Can only include files with absolute paths, not '") + included.data + "'"; } + else + throw std::string ("Malformed entry '") + line + "'"; } } - - in.close (); - return true; } - - return false; } //////////////////////////////////////////////////////////////////////////////// void Config::createDefaultRC (const std::string& rc, const std::string& data) { - // Create a sample .taskrc file. - std::stringstream contents; - contents << "# Task program configuration file.\n" - << "# For more documentation, see http://taskwarrior.org or try 'man task' and 'man taskrc'\n" - << "\n" - << "# Files\n" - << "data.location=" << data << "\n" - << "locking=on # Use file-level locking\n" - << "\n" - << "# Terminal\n" - << "curses=on # Use ncurses library to determine terminal width\n" - << "#defaultwidth=80 # Without ncurses, assumed width\n" - << "#editor=vi # Preferred text editor\n" - << "\n" - << "# Miscellaneous\n" - << "confirmation=yes # Confirmation on delete, big changes\n" - << "echo.command=yes # Details on command just run\n" - << "annotation.details=2 # Level of verbosity for annotations in reports\n" - << "next=2 # How many tasks per project in next report\n" - << "bulk=2 # > 2 tasks considered 'a lot', for confirmation\n" - << "nag=You have higher priority tasks. # Nag message to keep you honest\n" - << "\n" - << "# Dates\n" - << "dateformat=m/d/Y # Preferred input and display date format\n" - << "#reportdateformat=m/d/Y # Preferred input and display date format\n" - << "weekstart=Sunday # Sunday or Monday only\n" - << "displayweeknumber=yes # Show week numbers on calendar\n" - << "due=7 # Task is considered due in 7 days\n" - << "#calendar.details=yes # Calendar shows information for tasks w/due dates\n" - << "#calendar.details.report=list # Report to use when showing task information in cal\n" - << "#monthsperline=2 # Number of calendar months on a line\n" - << "\n" - << "# Color controls.\n" - << "color=on # Use color\n" - << "color.overdue=bold_red # Color of overdue tasks\n" - << "color.due=bold_yellow # Color of due tasks\n" - << "color.pri.H=bold # Color of priority:H tasks\n" - << "#color.pri.M=on_yellow # Color of priority:M tasks\n" - << "#color.pri.L=on_green # Color of priority:L tasks\n" - << "#color.pri.none=white on_blue # Color of priority: tasks\n" - << "color.active=bold_cyan # Color of active tasks\n" - << "color.tagged=yellow # Color of tagged tasks\n" - << "#color.tag.bug=yellow # Color of +bug tasks\n" - << "#color.project.garden=on_green # Color of project:garden tasks\n" - << "#color.keyword.car=on_blue # Color of description.contains:car tasks\n" - << "#color.recurring=on_red # Color of recur.any: tasks\n" - << "#color.header=bold_green # Color of header messages\n" - << "#color.footnote=bold_green # Color of footnote messages\n" - << "#color.alternate=on_rgb253 # Alternate color for line coloring\n" - << "color.calendar.today=black on cyan # Color of today in calendar\n" - << "color.calendar.due=black on green # Color of days with due tasks in calendar\n" - << "color.calendar.overdue=black on red # Color of days with overdue tasks in calendar\n" - << "color.calendar.weekend=black on white # Color of weekend days in calendar\n" - << "\n" - << "#shadow.file=/tmp/shadow.txt # Location of shadow file\n" - << "#shadow.command=list # Task command for shadow file\n" - << "#shadow.notify=on # Footnote when updated\n" - << "\n" - << "#default.project=foo # Unless otherwise specified\n" - << "#default.priority=M # Unless otherwise specified\n" - << "default.command=list # Unless otherwise specified\n" - << "\n" - << "alias.rm=delete\n" - << "\n" - << "# Fields: id,uuid,project,priority,priority_long,entry,entry_time,\n" - << "# start,entry_time,due,recur,recurrence_indicator,age,\n" - << "# age_compact,active,tags,tag_indicator,description,\n" - << "# description_only,end,end_time\n" - << "# Description: This report is ...\n" - << "# Sort: due+,priority-,project+\n" - << "# Filter: pro:x pri:H +bug limit:10\n" - << "\n" - << "# task long\n" - << "report.long.description=Lists all task, all data, matching the specified criteria\n" - << "report.long.columns=id,project,priority,entry,start,due,recur,age,tags,description\n" - << "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n" - << "report.long.sort=due+,priority-,project+\n" - << "report.long.filter=status:pending\n" - << "\n" - << "# task list\n" - << "report.list.description=Lists all tasks matching the specified criteria\n" - << "report.list.columns=id,project,priority,due,active,age,description\n" - << "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.list.sort=due+,priority-,project+\n" - << "report.list.filter=status:pending\n" - << "\n" - << "# task ls\n" - << "report.ls.description=Minimal listing of all tasks matching the specified criteria\n" - << "report.ls.columns=id,project,priority,description\n" - << "report.ls.labels=ID,Project,Pri,Description\n" - << "report.ls.sort=priority-,project+\n" - << "report.ls.filter=status:pending\n" - << "\n" - << "# task minimal\n" - << "report.minimal.description=A really minimal listing\n" - << "report.minimal.columns=id,project,description\n" - << "report.minimal.labels=ID,Project,Description\n" - << "report.minimal.sort=project+,description+\n" - << "report.minimal.filter=status:pending\n" - << "\n" - << "# task newest\n" - << "report.newest.description=Shows the newest tasks\n" - << "report.newest.columns=id,project,priority,due,active,age,description\n" - << "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.newest.sort=id-\n" - << "report.newest.filter=status:pending limit:10\n" - << "\n" - << "# task oldest\n" - << "report.oldest.description=Shows the oldest tasks\n" - << "report.oldest.columns=id,project,priority,due,active,age,description\n" - << "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.oldest.sort=id+\n" - << "report.oldest.filter=status:pending limit:10\n" - << "\n" - << "# task overdue\n" - << "report.overdue.description=Lists overdue tasks matching the specified criteria\n" - << "report.overdue.columns=id,project,priority,due,active,age,description\n" - << "report.overdue.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.overdue.sort=due+,priority-,project+\n" - << "report.overdue.filter=status:pending due.before:today\n" - << "\n" - << "# task active\n" - << "report.active.description=Lists active tasks matching the specified criteria\n" - << "report.active.columns=id,project,priority,due,active,age,description\n" - << "report.active.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.active.sort=due+,priority-,project+\n" - << "report.active.filter=status:pending start.any:\n" - << "\n" - << "# task completed\n" - << "report.completed.description=Lists completed tasks matching the specified criteria\n" - << "report.completed.columns=end,project,priority,age,description\n" - << "report.completed.labels=Complete,Project,Pri,Age,Description\n" - << "report.completed.sort=end+,priority-,project+\n" - << "report.completed.filter=status:completed\n" - << "\n" - << "# task recurring\n" - << "report.recurring.description=Lists recurring tasks matching the specified criteria\n" - << "report.recurring.columns=id,project,priority,due,recur,active,age,description\n" - << "report.recurring.labels=ID,Project,Pri,Due,Recur,Active,Age,Description\n" - << "report.recurring.sort=due+,priority-,project+\n" - << "report.recurring.filter=status:pending parent.any:\n" - << "\n" - << "# task waiting\n" - << "report.waiting.description=Lists all waiting tasks matching the specified criteria\n" - << "report.waiting.columns=id,project,priority,wait,age,description\n" - << "report.waiting.labels=ID,Project,Pri,Wait,Age,Description\n" - << "report.waiting.sort=wait+,priority-,project+\n" - << "report.waiting.filter=status:waiting\n" - << "\n" - << "# task all\n" - << "report.all.description=Lists all tasks matching the specified criteria\n" - << "report.all.columns=id,project,priority,due,active,age,description\n" - << "report.all.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.all.sort=due+,priority-,project+\n" - << "\n" - << "# task next\n" - << "report.next.description=Lists the most urgent tasks\n" - << "report.next.columns=id,project,priority,due,active,age,description\n" - << "report.next.labels=ID,Project,Pri,Due,Active,Age,Description\n" - << "report.next.sort=due+,priority-,project+\n" - << "report.next.filter=status:pending\n" - << "\n"; + // Override data.location in the defaults. + std::string::size_type loc = defaults.find ("data.location=~/.task"); + // loc+0^ +14^ +21^ - spit (rc, contents.str ()); + std::string contents = defaults.substr (0, loc + 14) + + data + + defaults.substr (loc + 21, std::string::npos); + + // Write out the new file. + if (! File::write (rc, contents)) + throw std::string ("Could not write to '") + rc + "'"; } //////////////////////////////////////////////////////////////////////////////// @@ -304,91 +362,13 @@ void Config::createDefaultData (const std::string& data) //////////////////////////////////////////////////////////////////////////////// void Config::setDefaults () { - set ("report.long.description", "Lists all task, all data, matching the specified criteria"); // TODO i18n - set ("report.long.columns", "id,project,priority,entry,start,due,recur,age,tags,description"); // TODO i18n - set ("report.long.labels", "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"); // TODO i18n - set ("report.long.sort", "due+,priority-,project+"); // TODO i18n - set ("report.long.filter", "status:pending"); // TODO i18n - - set ("report.list.description", "Lists all tasks matching the specified criteria"); // TODO i18n - set ("report.list.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.list.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.list.sort", "due+,priority-,project+"); // TODO i18n - set ("report.list.filter", "status:pending"); // TODO i18n - - set ("report.ls.description", "Short listing of all tasks matching the specified criteria"); // TODO i18n - set ("report.ls.columns", "id,project,priority,description"); // TODO i18n - set ("report.ls.labels", "ID,Project,Pri,Description"); // TODO i18n - set ("report.ls.sort", "priority-,project+"); // TODO i18n - set ("report.ls.filter", "status:pending"); // TODO i18n - - set ("report.minimal.description", "A really minimal listing"); // TODO i18n - set ("report.minimal.columns", "id,project,description"); // TODO i18n - set ("report.minimal.labels", "ID,Project,Description"); // TODO i18n - set ("report.minimal.sort", "project+,description+"); // TODO i18n - set ("report.minimal.filter", "status:pending"); // TODO i18n - - set ("report.newest.description", "Shows the newest tasks"); // TODO i18n - set ("report.newest.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.newest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.newest.sort", "id-"); // TODO i18n - set ("report.newest.filter", "status:pending limit:10"); // TODO i18n - - set ("report.oldest.description", "Shows the oldest tasks"); // TODO i18n - set ("report.oldest.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.oldest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.oldest.sort", "id+"); // TODO i18n - set ("report.oldest.filter", "status:pending limit:10"); // TODO i18n - - set ("report.overdue.description", "Lists overdue tasks matching the specified criteria"); // TODO i18n - set ("report.overdue.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.overdue.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.overdue.sort", "due+,priority-,project+"); // TODO i18n - set ("report.overdue.filter", "status:pending due.before:today"); // TODO i18n - - set ("report.active.description", "Lists active tasks matching the specified criteria"); // TODO i18n - set ("report.active.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.active.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.active.sort", "due+,priority-,project+"); // TODO i18n - set ("report.active.filter", "status:pending start.any:"); // TODO i18n - - set ("report.completed.description", "Lists completed tasks matching the specified criteria"); // TODO i18n - set ("report.completed.columns", "end,project,priority,age,description"); // TODO i18n - set ("report.completed.labels", "Complete,Project,Pri,Age,Description"); // TODO i18n - set ("report.completed.sort", "end+,priority-,project+"); // TODO i18n - set ("report.completed.filter", "status:completed"); // TODO i18n - - set ("report.recurring.description", "Lists recurring tasks matching the specified criteria"); // TODO i18n - set ("report.recurring.columns", "id,project,priority,due,recur,active,age,description"); // TODO i18n - set ("report.recurring.labels", "ID,Project,Pri,Due,Recur,Active,Age,Description"); // TODO i18n - set ("report.recurring.sort", "due+,priority-,project+"); // TODO i18n - set ("report.recurring.filter", "status:pending parent.any:"); // TODO i18n - - set ("report.waiting.description", "Lists all waiting tasks matching the specified criteria"); // TODO i18n - set ("report.waiting.columns", "id,project,priority,wait,age,description"); // TODO i18n - set ("report.waiting.labels", "ID,Project,Pri,Wait,Age,Description"); // TODO i18n - set ("report.waiting.sort", "wait+,priority-,project+"); // TODO i18n - set ("report.waiting.filter", "status:waiting"); // TODO i18n - - set ("report.all.description", "Lists all tasks matching the specified criteria"); // TODO i18n - set ("report.all.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.all.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.all.sort", "due+,priority-,project+"); // TODO i18n - - set ("report.next.description", "Lists the most urgent tasks"); // TODO i18n - set ("report.next.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.next.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.next.sort", "due+,priority-,project+"); // TODO i18n - set ("report.next.filter", "status:pending"); // TODO i18n - - set ("alias.rm", "delete"); // TODO i18n + parse (defaults); } //////////////////////////////////////////////////////////////////////////////// void Config::clear () { std::map ::clear (); - sequence.clear (); } //////////////////////////////////////////////////////////////////////////////// @@ -434,10 +414,11 @@ bool Config::get (const std::string& key, const bool default_value) if ((*this).find (key) != (*this).end ()) { std::string value = lowerCase ((*this)[key]); - if (value == "t" || // TODO i18n value == "true" || // TODO i18n value == "1" || // no i18n + value == "+" || // no i18n + value == "y" || // TODO i18n value == "yes" || // TODO i18n value == "on" || // TODO i18n value == "enable" || // TODO i18n @@ -498,40 +479,6 @@ void Config::all (std::vector& items) items.push_back (i->first); } -//////////////////////////////////////////////////////////////////////////////// -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 () { diff --git a/src/Config.h b/src/Config.h index f30c4e10f..c08a91c39 100644 --- a/src/Config.h +++ b/src/Config.h @@ -40,12 +40,21 @@ public: Config (const Config&); Config& operator= (const Config&); - bool load (const std::string&, int nest = 1); + void load (const std::string&, int nest = 1); + void parse (const std::string&, int nest = 1); + void createDefaultRC (const std::string&, const std::string&); void createDefaultData (const std::string&); void setDefaults (); void clear (); +/* + const std::string get (const std::string&); + const std::string getInteger (const std::string&); + const std::string getReal (const std::string&); + const std::string getBoolean (const std::string&); +*/ +// const std::string get (const char*); const std::string get (const char*, const char*); const std::string get (const std::string&); @@ -53,17 +62,17 @@ public: bool get (const std::string&, const bool); int get (const std::string&, const int); double get (const std::string&, const double); +// + void set (const std::string&, const int); 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; + static std::string defaults; }; #endif diff --git a/src/command.cpp b/src/command.cpp index 9907f9c53..00963cc08 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -606,7 +606,6 @@ int handleConfig (std::string &outs) } out << context.config.checkForDeprecatedColor (); - out << context.config.checkForDuplicates (); // TODO Check for referenced but missing theme files. // TODO Check for referenced but missing string files. diff --git a/src/tests/add.t b/src/tests/add.t index f18443978..00541d9f1 100755 --- a/src/tests/add.t +++ b/src/tests/add.t @@ -33,7 +33,8 @@ use Test::More tests => 13; # Create the rc file. if (open my $fh, '>', 'add.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "confirmation=off\n"; close $fh; ok (-r 'add.rc', 'Created add.rc'); } diff --git a/src/tests/annotate.t b/src/tests/annotate.t index 7d5eb259e..289699c3c 100755 --- a/src/tests/annotate.t +++ b/src/tests/annotate.t @@ -36,6 +36,7 @@ if (open my $fh, '>', 'annotate.rc') # Note: Use 'rrr' to guarantee a unique report name. Using 'r' conflicts # with 'recurring'. print $fh "data.location=.\n", + "confirmation=off\n", "report.rrr.description=rrr\n", "report.rrr.columns=id,description\n", "report.rrr.sort=id+\n"; diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index 3721b98a4..66df3d8e5 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -155,8 +155,8 @@ int main (int argc, char** argv) t.ok (good, "Att::mod (noword)"); good = true; - try {a6.mod ("fartwizzle");} catch (...) {good = false;} - t.notok (good, "Att::mod (fartwizzle)"); + try {a6.mod ("unrecognized");} catch (...) {good = false;} + t.notok (good, "Att::mod (unrecognized)"); // Att::parse Nibbler n (""); diff --git a/src/tests/basic.t b/src/tests/basic.t index 3ff3d58d4..c33a569f0 100755 --- a/src/tests/basic.t +++ b/src/tests/basic.t @@ -33,7 +33,8 @@ use Test::More tests => 7; # Create the rc file. if (open my $fh, '>', 'basic.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "default.command=\n"; close $fh; ok (-r 'basic.rc', 'Created basic.rc'); } diff --git a/src/tests/config.duplicate.t b/src/tests/config.duplicate.t deleted file mode 100755 index 996dbdcf2..000000000 --- a/src/tests/config.duplicate.t +++ /dev/null @@ -1,59 +0,0 @@ -#! /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 => 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 config}; -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; - diff --git a/src/tests/delete.t b/src/tests/delete.t index cf3f56042..97d992b52 100755 --- a/src/tests/delete.t +++ b/src/tests/delete.t @@ -34,6 +34,7 @@ use Test::More tests => 17; if (open my $fh, '>', 'delete.rc') { print $fh "data.location=.\n", + "confirmation=no\n", "echo.command=no\n"; close $fh; ok (-r 'delete.rc', 'Created delete.rc'); diff --git a/src/tests/sequence.t b/src/tests/sequence.t index d7d8ca417..58b3540bb 100755 --- a/src/tests/sequence.t +++ b/src/tests/sequence.t @@ -33,7 +33,8 @@ use Test::More tests => 28; # Create the rc file. if (open my $fh, '>', 'seq.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "confirmation=off\n"; close $fh; ok (-r 'seq.rc', 'Created seq.rc'); } diff --git a/src/tests/shadow.t b/src/tests/shadow.t index 09797075d..fcdacea8d 100755 --- a/src/tests/shadow.t +++ b/src/tests/shadow.t @@ -34,6 +34,7 @@ use Test::More tests => 22; if (open my $fh, '>', 'shadow.rc') { print $fh "data.location=.\n", + "confirmation=off\n", "shadow.file=./shadow.txt\n", "shadow.command=rc:shadow.rc stats\n", "shadow.notify=on\n";