From 636f6bfd960f16324277e4f61f8e18a2b4cbdc80 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 21 Feb 2015 12:36:06 +0100 Subject: [PATCH] CmdContext: Add initial implementation of the delete subcommand --- src/commands/CmdContext.cpp | 30 ++++++++++++++++++++++++++++++ src/commands/CmdContext.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index 95c4bcfa9..0ac4dc09f 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -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 & words, std::stringstre return 0; } +//////////////////////////////////////////////////////////////////////////////// +int CmdContext::deleteContext (std::vector & 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 () { diff --git a/src/commands/CmdContext.h b/src/commands/CmdContext.h index 63f1b2847..9a9c01d6a 100644 --- a/src/commands/CmdContext.h +++ b/src/commands/CmdContext.h @@ -37,6 +37,7 @@ public: int execute (std::string&); std::string joinWords (std::vector & words, unsigned int from, unsigned int to = 0); int defineContext (std::vector & words, std::stringstream& out); + int deleteContext (std::vector & words, std::stringstream& out); }; class CmdCompletionContext : public Command