diff --git a/src/commands/CmdShell.cpp b/src/commands/CmdShell.cpp index 21bd1779a..09e17d500 100644 --- a/src/commands/CmdShell.cpp +++ b/src/commands/CmdShell.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include 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 ::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 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 args; -// split (args, decoratedCommand, ' '); -// std::vector ::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 args; + split (args, decoratedCommand, ' '); + std::vector ::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; } diff --git a/src/en-US.h b/src/en-US.h index 7c19c23a0..a9312cd26 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -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." diff --git a/test/shell.t b/test/shell.t index 808cdc597..bfe722ca0 100755 --- a/test/shell.t +++ b/test/shell.t @@ -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;