TW-1827: Extract annotations from a task

- Thanks to Ryan.
This commit is contained in:
Paul Beckingham 2017-01-16 16:00:16 -05:00
parent fdd55bc422
commit 5206b4a84b
7 changed files with 40 additions and 0 deletions

View file

@ -32,6 +32,8 @@
(thanks to george js).
- TW-1820 Install with -DLANGUAGE=2 flag not work.
(thanks to E. Manuel Cerr'on Angeles)
- TW-1827 Extract annotations from a task
(thanks to Ryan).
- TW-1855 "Well-known" CA certificates not properly auto-loaded
(thanks to Flavio Poletti).
- TW-1857 Change Task::get call to the more efficient Task::has

1
NEWS
View file

@ -3,6 +3,7 @@ New Features in Taskwarrior 2.6.0
- The 'QUARTER' virutal tag was added.
- Improved compatibility with SmartOS, OmniOS and OpenIndiana.
- New DOM reference: annotations.count.
New Commands in Taskwarrior 2.6.0

View file

@ -167,6 +167,7 @@ bool getDOM (const std::string& name, Variant& value)
// <date>.second
//
// Annotations (entry is a date):
// annotations.count
// annotations.<N>.entry
// annotations.<N>.description
//
@ -298,6 +299,12 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
}
}
if (ref.data.size () && size == 2 && elements[0] == "annotations" && elements[1] == "count")
{
value = Variant (static_cast<int> (ref.getAnnotationCount ()));
return true;
}
if (ref.data.size () && size == 3 && elements[0] == "annotations")
{
auto annos = ref.getAnnotations ();

View file

@ -1159,6 +1159,7 @@ bool Lexer::isOperator (std::string& token, Lexer::Type& type)
// <date>.second
//
// Annotations (entry is a date):
// annotations.count
// annotations.<N>.entry
// annotations.<N>.description
//
@ -1259,6 +1260,13 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
if (isLiteral ("annotations", true, false) &&
isLiteral (".", false, false))
{
if (isLiteral ("count", false, false))
{
token = _text.substr (marker, _cursor - marker);
type = Lexer::Type::dom;
return true;
}
std::string extractedToken;
Lexer::Type extractedType;
if (isInteger (extractedToken, extractedType))

View file

@ -1032,6 +1032,17 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
int Task::getAnnotationCount () const
{
int count = 0;
for (auto& ann : data)
if (! ann.first.compare (0, 11, "annotation_", 11))
++count;
return count;
}
////////////////////////////////////////////////////////////////////////////////
bool Task::hasAnnotations () const
{

View file

@ -128,6 +128,7 @@ public:
std::vector <std::string> getTags () const;
void removeTag (const std::string&);
int getAnnotationCount () const;
bool hasAnnotations () const;
std::map <std::string, std::string> getAnnotations () const;
void setAnnotations (const std::map <std::string, std::string>&);

View file

@ -146,6 +146,16 @@ class TestDOM(TestCase):
code, out, err = self.t("_get 3.due.second")
self.assertEqual("0\n", out)
def test_dom_annotation_count_1(self):
""" DOM 1.annotation.count """
code, out, err = self.t("_get 1.annotations.count")
self.assertEqual("0\n", out)
def test_dom_annotation_count_3(self):
""" DOM 3.annotation.count """
code, out, err = self.t("_get 3.annotations.count")
self.assertEqual("1\n", out)
def test_dom_annotation_entry(self):
""" DOM 3.annotations.1.entry """
code, out, err = self.t("_get 3.annotations.1.entry")