CmdContext: Add support for setting context

This commit is contained in:
Tomas Babej 2015-02-21 18:04:08 +01:00 committed by Paul Beckingham
parent 5f3dd43893
commit 371ca27da0
2 changed files with 23 additions and 0 deletions

View file

@ -64,6 +64,8 @@ int CmdContext::execute (std::string& output)
rc = deleteContext(words, out); rc = deleteContext(words, out);
else if (subcommand == "list") else if (subcommand == "list")
rc = listContexts(words, out); rc = listContexts(words, out);
else
rc = setContext(words, out);
} }
output = out.str (); output = out.str ();
@ -207,6 +209,26 @@ int CmdContext::listContexts (std::vector <std::string>& words, std::stringstrea
return rc; return rc;
} }
////////////////////////////////////////////////////////////////////////////////
int CmdContext::setContext (std::vector <std::string>& words, std::stringstream& out)
{
// task context home
std::string value = words[0];
std::vector <std::string> contexts = getContexts ();
if (std::find (contexts.begin (), contexts.end (), value) == contexts.end())
throw format ("Context '{1}' not found.", value);
bool success = CmdConfig::setConfigVariable("context", value, false);
if (success)
out << "Context '" << value << "' applied." << "\n";
else
out << "Context '" << value << "' was not applied." << "\n";
return 0;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CmdCompletionContext::CmdCompletionContext () CmdCompletionContext::CmdCompletionContext ()
{ {

View file

@ -40,6 +40,7 @@ public:
int defineContext (std::vector <std::string>& words, std::stringstream& out); int defineContext (std::vector <std::string>& words, std::stringstream& out);
int deleteContext (std::vector <std::string>& words, std::stringstream& out); int deleteContext (std::vector <std::string>& words, std::stringstream& out);
int listContexts (std::vector <std::string>& words, std::stringstream& out); int listContexts (std::vector <std::string>& words, std::stringstream& out);
int setContext (std::vector <std::string>& words, std::stringstream& out);
}; };
class CmdCompletionContext : public Command class CmdCompletionContext : public Command