mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 19:17:19 +02:00
Feature #710
- Added feature #710, which adds an attribute modifier prefix to return the complement of a filtered set (thanks to Dan White). - Added missing description to the 'help' command. Signed-off-by: Paul Beckingham <paul@beckingham.net>
This commit is contained in:
parent
17f97651a3
commit
4b71fa73f8
10 changed files with 241 additions and 11 deletions
46
src/Att.cpp
46
src/Att.cpp
|
@ -113,6 +113,7 @@ Att::Att ()
|
|||
: mName ("")
|
||||
, mValue ("")
|
||||
, mMod ("")
|
||||
, mSense ("positive")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -122,6 +123,17 @@ Att::Att (const std::string& name, const std::string& mod, const std::string& va
|
|||
mName = name;
|
||||
mValue = value;
|
||||
mMod = mod;
|
||||
mSense = "positive";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Att::Att (const std::string& name, const std::string& mod, const std::string& value,
|
||||
const std::string& sense)
|
||||
{
|
||||
mName = name;
|
||||
mValue = value;
|
||||
mMod = mod;
|
||||
mSense = sense;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -134,6 +146,7 @@ Att::Att (const std::string& name, const std::string& mod, int value)
|
|||
mValue = s.str ();
|
||||
|
||||
mMod = mod;
|
||||
mSense = "positive";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -142,6 +155,7 @@ Att::Att (const std::string& name, const std::string& value)
|
|||
mName = name;
|
||||
mValue = value;
|
||||
mMod = "";
|
||||
mSense = "positive";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -154,6 +168,7 @@ Att::Att (const std::string& name, int value)
|
|||
mValue = s.str ();
|
||||
|
||||
mMod = "";
|
||||
mSense = "positive";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -162,6 +177,7 @@ Att::Att (const Att& other)
|
|||
mName = other.mName;
|
||||
mValue = other.mValue;
|
||||
mMod = other.mMod;
|
||||
mSense = other.mSense;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -172,6 +188,7 @@ Att& Att::operator= (const Att& other)
|
|||
mName = other.mName;
|
||||
mValue = other.mValue;
|
||||
mMod = other.mMod;
|
||||
mSense = other.mSense;
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
@ -180,9 +197,10 @@ Att& Att::operator= (const Att& other)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Att::operator== (const Att& other) const
|
||||
{
|
||||
return mName == other.mName &&
|
||||
mMod == other.mMod &&
|
||||
mValue == other.mValue;
|
||||
return mName == other.mName &&
|
||||
mMod == other.mMod &&
|
||||
mValue == other.mValue &&
|
||||
mSense == other.mSense;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -190,6 +208,20 @@ Att::~Att ()
|
|||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Att::logicSense (bool match) const
|
||||
{
|
||||
if (mSense == "positive")
|
||||
return match;
|
||||
else if (mSense == "negative")
|
||||
return ! match;
|
||||
else
|
||||
{
|
||||
context.debug ("mSense: " + mSense);
|
||||
throw ("unknown mSense " + mSense);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// For parsing.
|
||||
bool Att::valid (const std::string& input) const
|
||||
|
@ -515,6 +547,7 @@ void Att::parse (Nibbler& n)
|
|||
mName = "";
|
||||
mValue = "";
|
||||
mMod = "";
|
||||
mSense = "positive";
|
||||
|
||||
if (n.getUntilOneOf (".:", mName))
|
||||
{
|
||||
|
@ -524,6 +557,13 @@ void Att::parse (Nibbler& n)
|
|||
if (n.skip ('.'))
|
||||
{
|
||||
std::string mod;
|
||||
|
||||
if (n.skip ('~'))
|
||||
{
|
||||
context.debug ("using negative logic");
|
||||
mSense = "negative";
|
||||
}
|
||||
|
||||
if (n.getUntil (":", mod))
|
||||
{
|
||||
if (validMod (mod))
|
||||
|
|
|
@ -36,6 +36,7 @@ class Att
|
|||
public:
|
||||
Att ();
|
||||
Att (const std::string&, const std::string&, const std::string&);
|
||||
Att (const std::string&, const std::string&, const std::string&, const std::string&);
|
||||
Att (const std::string&, const std::string&, int);
|
||||
Att (const std::string&, const std::string&);
|
||||
Att (const std::string&, int);
|
||||
|
@ -44,6 +45,7 @@ public:
|
|||
bool operator== (const Att&) const;
|
||||
~Att ();
|
||||
|
||||
bool logicSense (bool match) const;
|
||||
bool valid (const std::string&) const;
|
||||
static bool validInternalName (const std::string&);
|
||||
static bool validModifiableName (const std::string&);
|
||||
|
@ -82,6 +84,7 @@ private:
|
|||
std::string mName;
|
||||
std::string mValue;
|
||||
std::string mMod;
|
||||
std::string mSense;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -861,12 +861,20 @@ void Context::autoFilter (Att& a, Filter& f)
|
|||
}
|
||||
|
||||
// Projects are matched left-most.
|
||||
else if (a.name () == "project" && a.mod () == "")
|
||||
else if (a.name () == "project" && (a.mod () == "" || a.mod () == "not"))
|
||||
{
|
||||
if (a.value () != "")
|
||||
{
|
||||
f.push_back (Att ("project", "startswith", a.value ()));
|
||||
debug ("auto filter: " + a.name () + ".startswith:" + a.value ());
|
||||
if (a.mod () == "not")
|
||||
{
|
||||
f.push_back (Att ("project", "startswith", a.value (), "negative"));
|
||||
debug ("auto filter: " + a.name () + ".~startswith:" + a.value ());
|
||||
}
|
||||
else
|
||||
{
|
||||
f.push_back (Att ("project", "startswith", a.value ()));
|
||||
debug ("auto filter: " + a.name () + ".startswith:" + a.value ());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -81,12 +81,12 @@ bool Filter::pass (const Record& record) const
|
|||
// are willing to invest a week understanding and testing it.
|
||||
if (att->modType (att->mod ()) == "positive")
|
||||
{
|
||||
if (! (pass || annotation_pass_count))
|
||||
if (! att->logicSense (pass || annotation_pass_count))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! (pass && annotation_fail_count == 0))
|
||||
if (! att->logicSense (pass && annotation_fail_count == 0))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ bool Filter::pass (const Record& record) const
|
|||
// An individual attribute match failure is enough to fail the filter.
|
||||
if ((r = record.find (att->name ())) != record.end ())
|
||||
{
|
||||
if (! att->match (r->second))
|
||||
if (! att->logicSense (att->match (r->second)))
|
||||
return false;
|
||||
}
|
||||
else if (! att->match (Att ()))
|
||||
|
|
|
@ -346,6 +346,9 @@ int longUsage (std::string& outs)
|
|||
<< " word" << "\n"
|
||||
<< " noword" << "\n"
|
||||
<< "\n"
|
||||
<< "Modifiers can be inverted with the ~ character:" << "\n"
|
||||
<< " project.~is is equivalent to project.isnt" << "\n"
|
||||
<< "\n"
|
||||
<< " For example:" << "\n"
|
||||
<< " task list due.before:eom priority.not:L" << "\n"
|
||||
<< "\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue