Commands - shell
- Migrated handleShell to CmdShell. - Note there is a segfault bug that will probably go away by itself when Context::parse is obsoleted.
This commit is contained in:
@@ -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 <std::string> 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 <std::string> 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user