mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Commands - shell
- Enabled the shell command. - Cleaned up unit tests.
This commit is contained in:
parent
7b0bf9f3c2
commit
5118b61f60
3 changed files with 37 additions and 35 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
#include <i18n.h>
|
||||||
#include <CmdShell.h>
|
#include <CmdShell.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
@ -39,7 +40,7 @@ CmdShell::CmdShell ()
|
||||||
{
|
{
|
||||||
_keyword = "shell";
|
_keyword = "shell";
|
||||||
_usage = "task shell";
|
_usage = "task shell";
|
||||||
_description = "Launches an interactive shell";
|
_description = STRING_CMD_SHELL_USAGE;
|
||||||
_read_only = false;
|
_read_only = false;
|
||||||
_displays_id = true;
|
_displays_id = true;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +48,6 @@ CmdShell::CmdShell ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdShell::execute (std::string&)
|
int CmdShell::execute (std::string&)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// Display some kind of welcome message.
|
// Display some kind of welcome message.
|
||||||
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
Color bold (Color::nocolor, Color::nocolor, false, true, false);
|
||||||
std::cout << (context.color () ? bold.colorize (PACKAGE_STRING) : PACKAGE_STRING)
|
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";
|
<< "Enter 'quit' (or 'bye', 'exit') to end the session.\n\n";
|
||||||
|
|
||||||
// Make a copy because context.clear will delete them.
|
// Make a copy because context.clear will delete them.
|
||||||
std::string permanentOverrides = " " + context.file_override
|
std::string permanent_overrides;
|
||||||
+ " " + context.var_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;
|
std::vector <std::string> quit_commands;
|
||||||
quit_commands.push_back ("quit");
|
quit_commands.push_back ("quit");
|
||||||
|
@ -74,7 +85,7 @@ int CmdShell::execute (std::string&)
|
||||||
|
|
||||||
command = "";
|
command = "";
|
||||||
std::getline (std::cin, 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
|
// When looking for the 'quit' command, use 'command', not
|
||||||
// 'decoratedCommand'.
|
// 'decoratedCommand'.
|
||||||
|
@ -86,15 +97,16 @@ int CmdShell::execute (std::string&)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// context.clear ();
|
context.clear ();
|
||||||
// std::vector <std::string> args;
|
|
||||||
// split (args, decoratedCommand, ' ');
|
std::vector <std::string> args;
|
||||||
// std::vector <std::string>::iterator arg;
|
split (args, decoratedCommand, ' ');
|
||||||
// for (arg = args.begin (); arg != args.end (); ++arg)
|
std::vector <std::string>::iterator arg;
|
||||||
// context.args.push_back (*arg);
|
for (arg = args.begin (); arg != args.end (); ++arg)
|
||||||
//
|
context.a3.capture (*arg);
|
||||||
// context.initialize (0, NULL);
|
|
||||||
// context.run ();
|
context.initialize (0, NULL);
|
||||||
|
context.run ();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (std::string& error)
|
catch (std::string& error)
|
||||||
|
@ -112,7 +124,6 @@ int CmdShell::execute (std::string&)
|
||||||
|
|
||||||
// No need to repeat any overrides after the shell quits.
|
// No need to repeat any overrides after the shell quits.
|
||||||
context.clearMessages ();
|
context.clearMessages ();
|
||||||
*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,7 @@
|
||||||
#define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'."
|
#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_USAGE "Imports JSON files."
|
||||||
#define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks."
|
#define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks."
|
||||||
|
#define STRING_CMD_SHELL_USAGE "Launches an interactive shell"
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."
|
#define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake."
|
||||||
|
|
30
test/shell.t
30
test/shell.t
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 10;
|
use Test::More tests => 5;
|
||||||
|
|
||||||
# Create the rc file.
|
# Create the rc file.
|
||||||
if (open my $fh, '>', 'shell.rc')
|
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};
|
$output = qx{echo "-- add foo\ninfo 1\n" | ../src/task rc:shell.rc shell};
|
||||||
like ($output, qr/Description\s+foo/, 'add/info working');
|
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';
|
unlink 'shell.rc';
|
||||||
ok (!-r 'shell.rc', 'Removed 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;
|
exit 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue