CmdContext: Add initial implementation of the delete subcommand

This commit is contained in:
Tomas Babej 2015-02-21 12:36:06 +01:00 committed by Paul Beckingham
parent e91063426a
commit 636f6bfd96
2 changed files with 31 additions and 0 deletions

View file

@ -55,8 +55,11 @@ int CmdContext::execute (std::string& output)
if (words.size () > 0)
{
std::string subcommand = words[0];
if (subcommand == "define")
rc = defineContext(words, out);
else if (subcommand == "delete")
rc = deleteContext(words, out);
}
output = out.str ();
@ -111,6 +114,33 @@ int CmdContext::defineContext (std::vector <std::string>& words, std::stringstre
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int CmdContext::deleteContext (std::vector <std::string>& words, std::stringstream& out)
{
// task context delete home
if (words.size () > 1)
{
std::string name = "context." + words[1];
bool confirmation = context.config.getBoolean ("confirmation");
int status = CmdConfig::unsetConfigVariable(name, confirmation);
std::string currentContext = context.config.get ("context");
if (currentContext == words[1])
CmdConfig::unsetConfigVariable("context", false);
if (status == 0)
out << "Context '" << words[1] << "' successfully undefined." << "\n";
else
out << "Context '" << words[1] << "' was not undefined." << "\n";
}
else
throw "You have to specify context name.";
return 0;
}
////////////////////////////////////////////////////////////////////////////////
CmdCompletionContext::CmdCompletionContext ()
{

View file

@ -37,6 +37,7 @@ public:
int execute (std::string&);
std::string joinWords (std::vector <std::string>& words, unsigned int from, unsigned int to = 0);
int defineContext (std::vector <std::string>& words, std::stringstream& out);
int deleteContext (std::vector <std::string>& words, std::stringstream& out);
};
class CmdCompletionContext : public Command