CmdTags: Displays 'No data found' instead of an empty table, if there are no inclusions

This commit is contained in:
Paul Beckingham 2016-04-17 10:32:16 -04:00
parent f52e6ea3aa
commit 22777067c4

View file

@ -29,44 +29,52 @@
#include <timew.h>
#include <Table.h>
#include <Color.h>
#include <algorithm>
#include <set>
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
int CmdTags (Rules& rules, Database& database)
{
// Generate a unique, ordered list of tags.
std::vector <std::string> tags;
std::set <std::string> tags;
for (auto& line : database.allLines ())
{
Interval interval;
interval.initialize (line);
if (line[0] == 'i')
{
Interval interval;
interval.initialize (line);
for (auto& tag : interval.tags ())
if (std::find (tags.begin (), tags.end (), tag) == tags.end ())
tags.push_back (tag);
for (auto& tag : interval.tags ())
tags.insert (tag);
}
}
// Shows all tags.
Table t;
t.width (1024);
t.colorHeader (Color ("underline"));
t.add ("Tag");
t.add ("Description");
// TODO Show all tag metadata.
for (auto& tag : tags)
if (tags.size ())
{
auto row = t.addRow ();
t.set (row, 0, tag, tagColor (rules, tag));
Table t;
t.width (1024);
t.colorHeader (Color ("underline"));
t.add ("Tag");
t.add ("Description");
// TODO Show all tag metadata.
auto name = std::string ("tag.") + tag + ".description";
t.set (row, 1, rules.has (name) ? rules.get (name) : "-");
for (auto& tag : tags)
{
auto row = t.addRow ();
t.set (row, 0, tag, tagColor (rules, tag));
auto name = std::string ("tag.") + tag + ".description";
t.set (row, 1, rules.has (name) ? rules.get (name) : "-");
}
std::cout << "\n"
<< t.render ()
<< "\n";
}
else
std::cout << "No data found.\n";
std::cout << "\n"
<< t.render ()
<< "\n";
return 0;
}