From dca4772f33a57f0c1a69249ef42c6fd54e06d262 Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Tue, 29 Dec 2009 02:46:16 +0100 Subject: [PATCH] New command config - version now only displays the version number and copyright notice - config displays the task configuration that version used to show - configuration variable longversion is not longer needed --- doc/man/task.1 | 7 ++- src/Cmd.cpp | 2 + src/Context.cpp | 1 + src/command.cpp | 93 ++++++++++++++++++++---------------- src/i18n.h | 1 + src/main.h | 1 + src/report.cpp | 4 ++ src/tests/color.deprecated.t | 7 ++- src/tests/config.duplicate.t | 2 +- src/tests/config.obsolete.t | 2 +- src/tests/rc.override.t | 4 +- 11 files changed, 74 insertions(+), 50 deletions(-) diff --git a/doc/man/task.1 b/doc/man/task.1 index 8f8df1090..0dad45a95 100644 --- a/doc/man/task.1 +++ b/doc/man/task.1 @@ -126,8 +126,11 @@ Displays all possible colors. .TP .B version -Shows the task version number and current settings in the task configuration -file. +Shows the task version number + +.TP +.B config +Shows the current settings in the task configuration file. .TP .B help diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 0274f89bf..b7d06f185 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -116,6 +116,7 @@ void Cmd::load () commands.push_back (context.stringtable.get (CMD_ANNOTATE, "annotate")); commands.push_back (context.stringtable.get (CMD_CALENDAR, "calendar")); commands.push_back (context.stringtable.get (CMD_COLORS, "colors")); + commands.push_back (context.stringtable.get (CMD_CONFIG, "config")); commands.push_back (context.stringtable.get (CMD_DELETE, "delete")); commands.push_back (context.stringtable.get (CMD_DONE, "done")); commands.push_back (context.stringtable.get (CMD_DUPLICATE, "duplicate")); @@ -196,6 +197,7 @@ bool Cmd::isReadOnlyCommand () command == "_version" || command == context.stringtable.get (CMD_CALENDAR, "calendar") || command == context.stringtable.get (CMD_COLORS, "colors") || + command == context.stringtable.get (CMD_CONFIG, "config") || command == context.stringtable.get (CMD_EXPORT, "export") || command == context.stringtable.get (CMD_HELP, "help") || command == context.stringtable.get (CMD_HISTORY, "history") || diff --git a/src/Context.cpp b/src/Context.cpp index 38a667bd4..192acd0d2 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -192,6 +192,7 @@ int Context::dispatch (std::string &out) else if (cmd.command == "tags") { rc = handleTags (out); } else if (cmd.command == "colors") { rc = handleColor (out); } else if (cmd.command == "version") { rc = handleVersion (out); } + else if (cmd.command == "config") { rc = handleConfig (out); } else if (cmd.command == "help") { rc = longUsage (out); } else if (cmd.command == "stats") { rc = handleReportStats (out); } else if (cmd.command == "info") { rc = handleInfo (out); } diff --git a/src/command.cpp b/src/command.cpp index 6d5228e54..d50bba3d4 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -446,44 +446,6 @@ int handleVersion (std::string &outs) "Documentation for task can be found using 'man task' and 'man taskrc', or " "at http://taskwarrior.org"); - std::vector all; - context.config.all (all); - - // Create a table for output. - Table table; - if (context.config.get ("longversion", true)) - { - table.setTableWidth (width); - table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); - table.addColumn ("Config variable"); - table.addColumn ("Value"); - - if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) - { - table.setColumnUnderline (0); - table.setColumnUnderline (1); - } - else - table.setTableDashedUnderline (); - - table.setColumnWidth (0, Table::minimum); - table.setColumnWidth (1, Table::flexible); - table.setColumnJustification (0, Table::left); - table.setColumnJustification (1, Table::left); - table.sortOn (0, Table::ascendingCharacter); - - foreach (i, all) - { - std::string value = context.config.get (*i); - if (value != "") - { - int row = table.addRow (); - table.addCell (row, 0, *i); - table.addCell (row, 1, value); - } - } - } - Color bold ("bold"); out << std::endl @@ -530,10 +492,61 @@ int handleVersion (std::string &outs) << "Copyright (C) 2006 - 2010, P. Beckingham." << std::endl << disclaimer.render () - << (context.config.get ("longversion", true) ? table.render () : "") << link.render () << std::endl; + outs = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// +int handleConfig (std::string &outs) +{ + int rc = 0; + std::stringstream out; + int width = context.getWidth (); + + std::vector all; + context.config.all (all); + + // Create a table for output. + Table table; + table.setTableWidth (width); + table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); + table.addColumn ("Config variable"); + table.addColumn ("Value"); + + if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) + { + table.setColumnUnderline (0); + table.setColumnUnderline (1); + } + else + table.setTableDashedUnderline (); + + table.setColumnWidth (0, Table::minimum); + table.setColumnWidth (1, Table::flexible); + table.setColumnJustification (0, Table::left); + table.setColumnJustification (1, Table::left); + table.sortOn (0, Table::ascendingCharacter); + + foreach (i, all) + { + std::string value = context.config.get (*i); + if (value != "") + { + int row = table.addRow (); + table.addCell (row, 0, *i); + table.addCell (row, 1, value); + } + } + + Color bold ("bold"); + + out << std::endl + << table.render () + << std::endl; + // Complain about configuration variables that are not recognized. // These are the regular configuration variables. // Note that there is a leading and trailing space, to make searching easier. @@ -545,7 +558,7 @@ int handleVersion (std::string &outs) "default.project defaultwidth due locale displayweeknumber echo.command " "locking monthsperline nag next project shadow.command shadow.file " "shadow.notify weekstart editor import.synonym.id import.synonym.uuid " - "longversion complete.all.projects complete.all.tags " + "complete.all.projects complete.all.tags " #ifdef FEATURE_SHELL "shell.prompt " #endif diff --git a/src/i18n.h b/src/i18n.h index 8a65808a5..a9e1be3ac 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -96,6 +96,7 @@ #define CMD_UNDO 227 #define CMD_VERSION 228 #define CMD_SHELL 229 +#define CMD_CONFIG 230 // 3xx Attributes #define ATT_PROJECT 300 diff --git a/src/main.h b/src/main.h index d69354e14..9e1f3f53a 100644 --- a/src/main.h +++ b/src/main.h @@ -70,6 +70,7 @@ int handleCompletionIDs (std::string &); int handleCompletionConfig (std::string &); int handleCompletionVersion (std::string &); int handleVersion (std::string &); +int handleConfig (std::string &); int handleDelete (std::string &); int handleStart (std::string &); int handleStop (std::string &); diff --git a/src/report.cpp b/src/report.cpp index 0e195e9e7..d01f720d5 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -185,6 +185,10 @@ int shortUsage (std::string &outs) table.addCell (row, 1, "task version"); table.addCell (row, 2, "Shows the task version number."); + row = table.addRow (); + table.addCell (row, 1, "task config"); + table.addCell (row, 2, "Shows the task configuration."); + row = table.addRow (); table.addCell (row, 1, "task help"); table.addCell (row, 2, "Shows the long usage text."); diff --git a/src/tests/color.deprecated.t b/src/tests/color.deprecated.t index 8fdf5aad9..d396840bc 100755 --- a/src/tests/color.deprecated.t +++ b/src/tests/color.deprecated.t @@ -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, '>', 'color.rc') @@ -41,9 +41,8 @@ if (open my $fh, '>', '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'); +my $output = qx{../task rc:color.rc config}; +like ($output, qr/that use deprecated underscores/ms, 'Deprecated color detected'); # Cleanup. unlink 'pending.data'; diff --git a/src/tests/config.duplicate.t b/src/tests/config.duplicate.t index dbe283145..996dbdcf2 100755 --- a/src/tests/config.duplicate.t +++ b/src/tests/config.duplicate.t @@ -41,7 +41,7 @@ if (open my $fh, '>', 'duplicate.rc') } # Test the add command. -my $output = qx{../task rc:duplicate.rc rc.longversion:off version}; +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'); diff --git a/src/tests/config.obsolete.t b/src/tests/config.obsolete.t index e767f172d..4c883a636 100755 --- a/src/tests/config.obsolete.t +++ b/src/tests/config.obsolete.t @@ -40,7 +40,7 @@ if (open my $fh, '>', 'obsolete.rc') } # Test the add command. -my $output = qx{../task rc:obsolete.rc version}; +my $output = qx{../task rc:obsolete.rc config}; like ($output, qr/Your .taskrc file contains these unrecognized variables:\n/, 'unsupported configuration variable'); diff --git a/src/tests/rc.override.t b/src/tests/rc.override.t index 928e7c223..e6b56466f 100755 --- a/src/tests/rc.override.t +++ b/src/tests/rc.override.t @@ -39,10 +39,10 @@ if (open my $fh, '>', 'rc.rc') ok (-r 'rc.rc', 'Created rc.rc'); } -my $output = qx{../task rc:rc.rc version}; +my $output = qx{../task rc:rc.rc config}; like ($output, qr/\sfoo\s+bar/, 'unmodified'); -$output = qx{../task rc:rc.rc rc.foo:baz version}; +$output = qx{../task rc:rc.rc rc.foo:baz config}; like ($output, qr/\sfoo\s+baz/, 'overridden'); unlink 'rc.rc';