mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
validateWriteContext: Refactor to return the underlying reason for invalidity directly
This commit is contained in:
parent
f5dce013ce
commit
5d8f8dac35
1 changed files with 8 additions and 13 deletions
|
@ -117,41 +117,36 @@ std::string CmdContext::joinWords (const std::vector <std::string>& words, unsig
|
||||||
// invalid due to a wrong modifier use, the modifier string will contain the
|
// invalid due to a wrong modifier use, the modifier string will contain the
|
||||||
// first invalid modifier.
|
// first invalid modifier.
|
||||||
//
|
//
|
||||||
bool CmdContext::validateWriteContext (const std::vector <A2>& lexedArgs, std::string& modifier_token)
|
bool CmdContext::validateWriteContext (const std::vector <A2>& lexedArgs, std::string& reason)
|
||||||
{
|
{
|
||||||
bool contains_or = false;
|
|
||||||
bool contains_modifier = false;
|
|
||||||
bool contains_tag_exclusion = false;
|
|
||||||
|
|
||||||
for (auto &arg: lexedArgs) {
|
for (auto &arg: lexedArgs) {
|
||||||
if (arg._lextype == Lexer::Type::op)
|
if (arg._lextype == Lexer::Type::op)
|
||||||
if (arg.attribute ("raw") == "or")
|
if (arg.attribute ("raw") == "or")
|
||||||
{
|
{
|
||||||
contains_or = true;
|
reason = "contains the 'OR' operator";
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg._lextype == Lexer::Type::pair) {
|
if (arg._lextype == Lexer::Type::pair) {
|
||||||
auto modifier = arg.attribute ("modifier");
|
auto modifier = arg.attribute ("modifier");
|
||||||
if (modifier != "" && modifier != "is" && modifier != "equals")
|
if (modifier != "" && modifier != "is" && modifier != "equals")
|
||||||
{
|
{
|
||||||
contains_modifier = true;
|
reason = format ("contains an attribute modifier '{1}'", arg.attribute ("raw"));
|
||||||
modifier_token = arg.attribute ("raw");
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg._lextype == Lexer::Type::tag) {
|
if (arg._lextype == Lexer::Type::tag) {
|
||||||
if (arg.attribute ("sign") == "-")
|
if (arg.attribute ("sign") == "-")
|
||||||
{
|
{
|
||||||
contains_tag_exclusion = true;
|
reason = format ("contains tag exclusion '{1}'", arg.attribute ("raw"));
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return not contains_or and not contains_modifier and not contains_tag_exclusion;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue