mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 19:03:07 +02:00
CmdContext: Add support for setting context
This commit is contained in:
parent
5f3dd43893
commit
371ca27da0
2 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue