Commands - shell

- Enabled the shell command.
- Cleaned up unit tests.
This commit is contained in:
Paul Beckingham 2011-09-02 00:28:31 -04:00
parent 7b0bf9f3c2
commit 5118b61f60
3 changed files with 37 additions and 35 deletions

View file

@ -30,6 +30,7 @@
#include <Color.h>
#include <Context.h>
#include <text.h>
#include <i18n.h>
#include <CmdShell.h>
extern Context context;
@ -39,7 +40,7 @@ CmdShell::CmdShell ()
{
_keyword = "shell";
_usage = "task shell";
_description = "Launches an interactive shell";
_description = STRING_CMD_SHELL_USAGE;
_read_only = false;
_displays_id = true;
}
@ -47,7 +48,6 @@ CmdShell::CmdShell ()
////////////////////////////////////////////////////////////////////////////////
int CmdShell::execute (std::string&)
{
/*
// Display some kind of welcome message.
Color bold (Color::nocolor, Color::nocolor, false, true, false);
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
@ -57,8 +57,19 @@ int CmdShell::execute (std::string&)
<< "Enter 'quit' (or 'bye', 'exit') to end the session.\n\n";
// Make a copy because context.clear will delete them.
std::string permanentOverrides = " " + context.file_override
+ " " + context.var_overrides;
std::string permanent_overrides;
std::vector <Arg>::iterator i;
for (i = context.a3.begin (); i != context.a3.end (); ++i)
{
if (i->_category == Arg::cat_rc ||
i->_category == Arg::cat_override)
{
if (i != context.a3.begin ())
permanent_overrides += " ";
permanent_overrides += i->_raw;
}
}
std::vector <std::string> quit_commands;
quit_commands.push_back ("quit");
@ -74,7 +85,7 @@ int CmdShell::execute (std::string&)
command = "";
std::getline (std::cin, command);
std::string decoratedCommand = trim (command + permanentOverrides);
std::string decoratedCommand = "task " + trim (command + permanent_overrides);
// When looking for the 'quit' command, use 'command', not
// 'decoratedCommand'.
@ -86,15 +97,16 @@ int CmdShell::execute (std::string&)
{
try
{
// context.clear ();
// std::vector <std::string> args;
// split (args, decoratedCommand, ' ');
// std::vector <std::string>::iterator arg;
// for (arg = args.begin (); arg != args.end (); ++arg)
// context.args.push_back (*arg);
//
// context.initialize (0, NULL);
// context.run ();
context.clear ();
std::vector <std::string> args;
split (args, decoratedCommand, ' ');
std::vector <std::string>::iterator arg;
for (arg = args.begin (); arg != args.end (); ++arg)
context.a3.capture (*arg);
context.initialize (0, NULL);
context.run ();
}
catch (std::string& error)
@ -112,7 +124,6 @@ int CmdShell::execute (std::string&)
// No need to repeat any overrides after the shell quits.
context.clearMessages ();
*/
return 0;
}

View file

@ -311,6 +311,7 @@
#define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'."
#define STRING_CMD_IMPORT_USAGE "Imports JSON files."
#define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks."
#define STRING_CMD_SHELL_USAGE "Launches an interactive shell"
// Config
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."

View file

@ -28,7 +28,7 @@
use strict;
use warnings;
use Test::More tests => 10;
use Test::More tests => 5;
# Create the rc file.
if (open my $fh, '>', 'shell.rc')
@ -48,27 +48,17 @@ like ($output, qr/testprompt>/, 'custom prompt is being used');
$output = qx{echo "-- add foo\ninfo 1\n" | ../src/task rc:shell.rc shell};
like ($output, qr/Description\s+foo/, 'add/info working');
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'completed.data';
ok (!-r 'completed.data', 'Removed completed.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'response.txt';
ok (!-r 'response.txt', 'Removed response.txt');
unlink 'backlog.data';
ok (!-r 'backlog.data', 'Removed backlog.data');
unlink 'synch.key';
ok (!-r 'synch.key', 'Removed synch.key');
unlink 'shell.rc';
ok (!-r 'shell.rc', 'Removed shell.rc');
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data synch.key shell.rc);
ok (! -r 'pending.data' &&
! -r 'completed.data' &&
! -r 'undo.data' &&
! -r 'backlog.data' &&
! -r 'synch_key.data' &&
! -r 'shell.rc', 'Cleanup');
exit 0;