mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
CmdContext: Validate context's filter upon definition
This commit is contained in:
parent
e19c99ce1e
commit
85d0e1789a
9 changed files with 47 additions and 2 deletions
|
@ -26,9 +26,11 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <Context.h>
|
||||
#include <Filter.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <i18n.h>
|
||||
#include <util.h>
|
||||
#include <text.h>
|
||||
#include <CmdContext.h>
|
||||
#include <CmdConfig.h>
|
||||
|
@ -128,15 +130,35 @@ std::vector <std::string> CmdContext::getContexts ()
|
|||
int CmdContext::defineContext (std::vector <std::string>& words, std::stringstream& out)
|
||||
{
|
||||
int rc = 0;
|
||||
bool confirmation = context.config.getBoolean ("confirmation");
|
||||
|
||||
if (words.size () > 2)
|
||||
{
|
||||
std::string name = "context." + words[1];
|
||||
std::string value = joinWords (words, 2);
|
||||
// TODO: Check if the value is a proper filter
|
||||
|
||||
// Check if the value is a proper filter by filtering current pending.data
|
||||
Filter filter;
|
||||
std::vector <Task> filtered;
|
||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||
|
||||
try
|
||||
{
|
||||
context.cli.addRawFilter ("( " + value + " )");
|
||||
filter.subset (pending, filtered);
|
||||
}
|
||||
catch (std::string exception)
|
||||
{
|
||||
throw format (STRING_CMD_CONTEXT_DEF_ABRT2, exception);
|
||||
}
|
||||
|
||||
// Make user explicitly confirm filters that are matching no pending tasks
|
||||
if (filtered.size () == 0)
|
||||
if (confirmation &&
|
||||
! confirm (format (STRING_CMD_CONTEXT_DEF_CONF, value)))
|
||||
throw std::string (STRING_CMD_CONTEXT_DEF_ABRT);
|
||||
|
||||
// Set context definition config variable
|
||||
bool confirmation = context.config.getBoolean ("confirmation");
|
||||
bool success = CmdConfig::setConfigVariable (name, value, confirmation);
|
||||
|
||||
if (success)
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -574,6 +574,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -565,6 +565,8 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -564,6 +564,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
|
@ -565,6 +565,9 @@
|
|||
#define STRING_CMD_CONTEXT_DEF_SUCC "Context '{1}' defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_FAIL "Context '{1}' not defined."
|
||||
#define STRING_CMD_CONTEXT_DEF_USAG "Both context name and its definition must be provided."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT "Context definiton aborted."
|
||||
#define STRING_CMD_CONTEXT_DEF_ABRT2 "Filter validation failed: {1}"
|
||||
#define STRING_CMD_CONTEXT_DEF_CONF "The filter '{1}' matches 0 pending tasks. Do you wish to continue?"
|
||||
#define STRING_CMD_CONTEXT_DEL_SUCC "Context '{1}' deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_FAIL "Context '{1}' not deleted."
|
||||
#define STRING_CMD_CONTEXT_DEL_USAG "Context name needs to be specified."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue