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
This commit is contained in:
Federico Hernandez 2009-12-29 02:46:16 +01:00
parent 48daf13d7f
commit dca4772f33
11 changed files with 74 additions and 50 deletions

View file

@ -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

View file

@ -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") ||

View file

@ -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); }

View file

@ -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 <std::string> 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 <std::string> 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

View file

@ -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

View file

@ -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 &);

View file

@ -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.");

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, '>', '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';

View file

@ -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');

View file

@ -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');

View file

@ -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';