From 09fe5be0862d6ad9e2ab1e77e7a420d5f26d583c Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 21 Feb 2015 18:50:14 +0100 Subject: [PATCH] CmdContext: Add show subcommand --- src/commands/CmdContext.cpp | 19 +++++++++++++++++++ src/commands/CmdContext.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/commands/CmdContext.cpp b/src/commands/CmdContext.cpp index 1d533d3c0..5378c51d2 100644 --- a/src/commands/CmdContext.cpp +++ b/src/commands/CmdContext.cpp @@ -66,6 +66,8 @@ int CmdContext::execute (std::string& output) rc = listContexts(words, out); else if (subcommand == "none") rc = unsetContext(words, out); + else if (subcommand == "show") + rc = showContext(words, out); else rc = setContext(words, out); } @@ -231,6 +233,23 @@ int CmdContext::setContext (std::vector & words, std::stringstream& return 0; } +//////////////////////////////////////////////////////////////////////////////// +int CmdContext::showContext (std::vector & words, std::stringstream& out) +{ + // task context show + std::string currentContext = context.config.get ("context"); + + if (currentContext == "") + out << "No context is currently applied." << "\n"; + else + { + std::string currentFilter = context.config.get ("context." + currentContext); + out << format ("Context '{1}' with filter '{2}' is currently applied.", currentContext, currentFilter) << "\n"; + } + + return 0; +} + //////////////////////////////////////////////////////////////////////////////// int CmdContext::unsetContext (std::vector & words, std::stringstream& out) { diff --git a/src/commands/CmdContext.h b/src/commands/CmdContext.h index 2a35029b8..4d0f1df75 100644 --- a/src/commands/CmdContext.h +++ b/src/commands/CmdContext.h @@ -41,6 +41,7 @@ public: int deleteContext (std::vector & words, std::stringstream& out); int listContexts (std::vector & words, std::stringstream& out); int setContext (std::vector & words, std::stringstream& out); + int showContext (std::vector & words, std::stringstream& out); int unsetContext (std::vector & words, std::stringstream& out); };