diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 5751cacf8..eba754455 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -164,7 +164,6 @@ void Cmd::load () commands.push_back ("log"); commands.push_back ("prepend"); commands.push_back ("projects"); - commands.push_back ("shell"); commands.push_back ("start"); commands.push_back ("stats"); commands.push_back ("stop"); @@ -256,7 +255,6 @@ bool Cmd::isReadOnlyCommand () command == "help" || command == "projects" || command == "push" || - command == "shell" || command == "stats" || command == "summary" || command == "timesheet" || diff --git a/src/Context.cpp b/src/Context.cpp index 601f5787b..6df27fcb5 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -276,7 +276,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "export.yaml") { rc = handleExportYAML (out); } else if (cmd.command == "import") { rc = handleImport (out); } else if (cmd.command == "duplicate") { rc = handleDuplicate (out); } - else if (cmd.command == "shell") { handleShell ( ); } else if (cmd.command == "undo") { handleUndo ( ); } else if (cmd.command == "merge") { tdb.gc (); handleMerge (out); } diff --git a/src/command.cpp b/src/command.cpp index f4cafb461..372f81c1d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1792,74 +1792,6 @@ int handleIds (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -// TODO Obsolete. -void handleShell () -{ - // 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) - << " shell\n\n" - << "Enter any task command (such as 'list'), or hit 'Enter'.\n" - << "There is no need to include the 'task' command itself.\n" - << "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::vector quit_commands; - quit_commands.push_back ("quit"); - quit_commands.push_back ("exit"); - quit_commands.push_back ("bye"); - - std::string command; - bool keepGoing = true; - - do - { - std::cout << context.config.get ("shell.prompt") << " "; - - command = ""; - std::getline (std::cin, command); - std::string decoratedCommand = trim (command + permanentOverrides); - - // When looking for the 'quit' command, use 'command', not - // 'decoratedCommand'. - if (std::find (quit_commands.begin (), quit_commands.end (), lowerCase (command)) != quit_commands.end ()) - { - keepGoing = false; - } - else - { - try - { - context.clear (); - std::vector args; - split (args, decoratedCommand, ' '); - foreach (arg, args) context.args.push_back (*arg); - - context.initialize (0, NULL); - context.run (); - } - - catch (std::string& error) - { - std::cout << error << "\n"; - } - - catch (...) - { - std::cerr << "Unknown error." << "\n"; - } - } - } - while (keepGoing && !std::cin.eof ()); - - // No need to repeat any overrides after the shell quits. - context.clearMessages (); -} - //////////////////////////////////////////////////////////////////////////////// int handleColor (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index d5a4736cb..1355ada38 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -14,6 +14,7 @@ set (commands_SRCS Command.cpp Command.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h CmdLogo.cpp CmdLogo.h + CmdShell.cpp CmdShell.h CmdShow.cpp CmdShow.h CmdTags.cpp CmdTags.h CmdTip.cpp CmdTip.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 0df0b5191..1d7bf0244 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -131,10 +131,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 1, "task undo"); view.set (row, 2, "Reverts the most recent action."); - row = view.addRow (); - view.set (row, 1, "task shell"); - view.set (row, 2, "Launches an interactive shell."); - row = view.addRow (); view.set (row, 1, "task duplicate ID [tags] [attrs] [desc...]"); view.set (row, 2, "Duplicates the specified task, and allows modifications."); diff --git a/src/commands/CmdShell.cpp b/src/commands/CmdShell.cpp new file mode 100644 index 000000000..15d9040b2 --- /dev/null +++ b/src/commands/CmdShell.cpp @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdShell::CmdShell () +{ + _keyword = "shell"; + _usage = "task shell"; + _description = "Launches an interactive shell"; + _read_only = false; + _displays_id = true; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdShell::execute (const std::string& command_line, std::string& output) +{ + // 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) + << " shell\n\n" + << "Enter any task command (such as 'list'), or hit 'Enter'.\n" + << "There is no need to include the 'task' command itself.\n" + << "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::vector quit_commands; + quit_commands.push_back ("quit"); + quit_commands.push_back ("exit"); + quit_commands.push_back ("bye"); + + std::string command; + bool keepGoing = true; + + do + { + std::cout << context.config.get ("shell.prompt") << " "; + + command = ""; + std::getline (std::cin, command); + std::string decoratedCommand = trim (command + permanentOverrides); + + // When looking for the 'quit' command, use 'command', not + // 'decoratedCommand'. + if (std::find (quit_commands.begin (), quit_commands.end (), lowerCase (command)) != quit_commands.end ()) + { + keepGoing = false; + } + else + { + 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 (); + } + + catch (std::string& error) + { + std::cout << error << "\n"; + } + + catch (...) + { + std::cerr << "Unknown error." << "\n"; + } + } + } + while (keepGoing && !std::cin.eof ()); + + // No need to repeat any overrides after the shell quits. + context.clearMessages (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdShell.h b/src/commands/CmdShell.h new file mode 100644 index 000000000..d54c6cf48 --- /dev/null +++ b/src/commands/CmdShell.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// taskwarrior - a command line task list manager. +// +// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the +// +// Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, +// Boston, MA +// 02110-1301 +// USA +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_CMDSHELL +#define INCLUDED_CMDSHELL +#define L10N // Localization complete. + +#include +#include + +class CmdShell : public Command +{ +public: + CmdShell (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index f00108e42..8d011cfe5 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ void Command::factory (std::map & all) c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; + c = new CmdShell (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTip (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 845085f37..4aefcdc44 100644 --- a/src/main.h +++ b/src/main.h @@ -79,7 +79,6 @@ void handleUndo (); void handleMerge (std::string&); void handlePush (std::string&); void handlePull (std::string&); -void handleShell (); int deltaAppend (Task&); int deltaPrepend (Task&); int deltaDescription (Task&);