CmdContext: Add support for setting context
This commit is contained in:
committed by
Paul Beckingham
parent
5f3dd43893
commit
371ca27da0
@@ -64,6 +64,8 @@ int CmdContext::execute (std::string& output)
|
||||
rc = deleteContext(words, out);
|
||||
else if (subcommand == "list")
|
||||
rc = listContexts(words, out);
|
||||
else
|
||||
rc = setContext(words, out);
|
||||
}
|
||||
|
||||
output = out.str ();
|
||||
@@ -207,6 +209,26 @@ int CmdContext::listContexts (std::vector <std::string>& words, std::stringstrea
|
||||
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 ()
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
int defineContext (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 setContext (std::vector <std::string>& words, std::stringstream& out);
|
||||
};
|
||||
|
||||
class CmdCompletionContext : public Command
|
||||
|
||||
Reference in New Issue
Block a user