mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
Integration - mod
- Now handles blank modifiers. Like it should.
This commit is contained in:
parent
25d27bec93
commit
a04bfc468b
2 changed files with 86 additions and 44 deletions
57
src/Att.cpp
57
src/Att.cpp
|
@ -215,7 +215,8 @@ bool Att::validNameValue (
|
|||
std::string writableMod = mod;
|
||||
std::string writableValue = value;
|
||||
bool status = Att::validNameValue (writableName, writableMod, writableValue);
|
||||
|
||||
/*
|
||||
// TODO Is this even worth doing?
|
||||
if (name != writableName)
|
||||
throw std::string ("The attribute '") + name + "' was not fully qualified.";
|
||||
|
||||
|
@ -224,7 +225,7 @@ bool Att::validNameValue (
|
|||
|
||||
if (value != writableValue)
|
||||
throw std::string ("The value '") + value + "' was not fully qualified.";
|
||||
|
||||
*/
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -262,6 +263,8 @@ bool Att::validNameValue (
|
|||
name = matches[0];
|
||||
|
||||
// Second, guess at the modifier name.
|
||||
if (mod != "")
|
||||
{
|
||||
candidates.clear ();
|
||||
for (unsigned i = 0; i < NUM_MODIFIER_NAMES; ++i)
|
||||
candidates.push_back (modifierNames[i]);
|
||||
|
@ -270,11 +273,11 @@ bool Att::validNameValue (
|
|||
autoComplete (mod, candidates, matches);
|
||||
|
||||
if (matches.size () == 0)
|
||||
throw std::string ("Unrecognized modifier '") + name + "'";
|
||||
throw std::string ("Unrecognized modifier '") + mod + "'";
|
||||
|
||||
else if (matches.size () != 1)
|
||||
{
|
||||
std::string error = "Ambiguous modifier '" + name + "' - could be either of "; // TODO i18n
|
||||
std::string error = "Ambiguous modifier '" + mod + "' - could be either of "; // TODO i18n
|
||||
|
||||
std::string combined;
|
||||
join (combined, ", ", matches);
|
||||
|
@ -284,12 +287,18 @@ bool Att::validNameValue (
|
|||
}
|
||||
|
||||
mod = matches[0];
|
||||
}
|
||||
|
||||
// Thirdly, make sure the value has the expected form or values.
|
||||
if (name == "project" && !noSpaces (value))
|
||||
if (name == "project")
|
||||
{
|
||||
if (!noSpaces (value))
|
||||
throw std::string ("The '") + name + "' attribute may not contain spaces.";
|
||||
}
|
||||
|
||||
else if (name == "priority" && value != "")
|
||||
else if (name == "priority")
|
||||
{
|
||||
if (value != "")
|
||||
{
|
||||
value = upperCase (value);
|
||||
if (value != "H" &&
|
||||
|
@ -299,24 +308,44 @@ bool Att::validNameValue (
|
|||
value +
|
||||
"\" is not a valid priority. Use H, M, L or leave blank.";
|
||||
}
|
||||
}
|
||||
|
||||
else if (name == "description" && (value != "" || !noVerticalSpace (value)))
|
||||
else if (name == "description")
|
||||
{
|
||||
if (value != "" || !noVerticalSpace (value))
|
||||
throw std::string ("The '") + name + "' attribute must not be blank, and must not contain vertical white space.";
|
||||
}
|
||||
|
||||
else if ((name == "fg" || name == "bg") && value != "")
|
||||
else if (name == "fg" || name == "bg")
|
||||
{
|
||||
if (value != "")
|
||||
Text::guessColor (value);
|
||||
}
|
||||
|
||||
else if (name == "due" && value != "")
|
||||
else if (name == "due")
|
||||
{
|
||||
if (value != "")
|
||||
Date (value);
|
||||
}
|
||||
|
||||
else if (name == "until" && value != "")
|
||||
else if (name == "until")
|
||||
{
|
||||
if (value != "")
|
||||
Date (value);
|
||||
}
|
||||
|
||||
else if (name == "recur" && value != "")
|
||||
else if (name == "recur")
|
||||
{
|
||||
if (value != "")
|
||||
Duration (value);
|
||||
}
|
||||
|
||||
else if (name == "limit" && (value == "" || !digitsOnly (value)))
|
||||
// TODO Not ready for prime time.
|
||||
else if (name == "limit")
|
||||
{
|
||||
if (value == "" || !digitsOnly (value))
|
||||
throw std::string ("The '") + name + "' attribute must be an integer.";
|
||||
}
|
||||
|
||||
// Some attributes are intended to be private.
|
||||
else if (name == "entry" ||
|
||||
|
@ -326,9 +355,11 @@ bool Att::validNameValue (
|
|||
name == "imask" ||
|
||||
name == "uuid" ||
|
||||
name == "status")
|
||||
{
|
||||
throw std::string ("\"") +
|
||||
name +
|
||||
"\" is not an attribute you may modify directly.";
|
||||
}
|
||||
|
||||
else
|
||||
throw std::string ("'") + name + "' is an unrecognized attribute.";
|
||||
|
@ -509,7 +540,7 @@ std::string Att::composeF4 () const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::mod (const std::string& input)
|
||||
{
|
||||
if (!validMod (input))
|
||||
if (input != "" && !validMod (input))
|
||||
throw std::string ("The name '") + input + "' is not a valid modifier"; // TODO i18n
|
||||
|
||||
mMod = input;
|
||||
|
|
|
@ -383,6 +383,7 @@ std::cout << "[1;31m# parse tag removal '" << *arg << "'[0m" << std::endl;
|
|||
tagRemovals.push_back (arg->substr (1, std::string::npos));
|
||||
}
|
||||
|
||||
// Atributes - name[.mod]:[value]
|
||||
else if (attribute.valid (*arg))
|
||||
{
|
||||
std::cout << "[1;31m# parse attribute '" << *arg << "'[0m" << std::endl;
|
||||
|
@ -390,6 +391,16 @@ std::cout << "[1;31m# parse attribute '" << *arg << "'[0m" << std::endl;
|
|||
foundSomethingAfterSequence = true;
|
||||
|
||||
attribute.parse (*arg);
|
||||
|
||||
// There has to be a better way. And it starts with a fresh coffee.
|
||||
std::string name = attribute.name ();
|
||||
std::string mod = attribute.mod ();
|
||||
std::string value = attribute.value ();
|
||||
attribute.validNameValue (name, mod, value);
|
||||
attribute.name (name);
|
||||
attribute.mod (mod);
|
||||
attribute.value (value);
|
||||
|
||||
task[attribute.name ()] = attribute;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue