From 22777067c4c4f378941b45461f707c8cb3277845 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Apr 2016 10:32:16 -0400 Subject: [PATCH] CmdTags: Displays 'No data found' instead of an empty table, if there are no inclusions --- src/commands/CmdTags.cpp | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index 669c1731..46459855 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -29,44 +29,52 @@ #include #include #include -#include +#include #include //////////////////////////////////////////////////////////////////////////////// int CmdTags (Rules& rules, Database& database) { // Generate a unique, ordered list of tags. - std::vector tags; + std::set 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; }