• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.93
/src/commands/CmdTags.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <CmdTags.h>
31
#include <Context.h>
32
#include <Filter.h>
33
#include <Table.h>
34
#include <format.h>
35
#include <stdlib.h>
36
#include <util.h>
37

38
#include <sstream>
39
#include <vector>
40

41
////////////////////////////////////////////////////////////////////////////////
42
CmdTags::CmdTags() {
4,389✔
43
  _keyword = "tags";
4,389✔
44
  _usage = "task <filter> tags";
4,389✔
45
  _description = "Shows a list of all tags used";
4,389✔
46
  _read_only = true;
4,389✔
47
  _displays_id = false;
4,389✔
48
  _needs_gc = true;
4,389✔
49
  _uses_context = true;
4,389✔
50
  _accepts_filter = true;
4,389✔
51
  _accepts_modifications = false;
4,389✔
52
  _accepts_miscellaneous = false;
4,389✔
53
  _category = Command::Category::metadata;
4,389✔
54
}
4,389✔
55

56
////////////////////////////////////////////////////////////////////////////////
57
int CmdTags::execute(std::string& output) {
2✔
58
  int rc = 0;
2✔
59
  std::stringstream out;
2✔
60

61
  // Get all the tasks.
62
  auto tasks = Context::getContext().tdb2.pending_tasks();
2✔
63

64
  if (Context::getContext().config.getBoolean("list.all.tags"))
2✔
65
    for (auto& task : Context::getContext().tdb2.completed_tasks()) tasks.push_back(task);
2✔
66

67
  int quantity = tasks.size();
2✔
68

69
  // Apply filter.
70
  Filter filter;
2✔
71
  std::vector<Task> filtered;
2✔
72
  filter.subset(tasks, filtered);
2✔
73

74
  // Scan all the tasks for their project name, building a map using project
75
  // names as keys.
76
  std::map<std::string, int> unique;
2✔
77
  for (auto& task : filtered) {
5✔
78
    for (auto& tag : task.getTags())
6✔
79
      if (unique.find(tag) != unique.end())
3✔
UNCOV
80
        unique[tag]++;
×
81
      else
82
        unique[tag] = 1;
6✔
83
  }
84

85
  if (unique.size()) {
2✔
86
    // Render a list of tags names from the map.
87
    Table view;
2✔
88
    view.width(Context::getContext().getWidth());
2✔
89
    view.add("Tag");
2✔
90
    view.add("Count", false);
2✔
91
    setHeaderUnderline(view);
2✔
92

93
    Color bold;
2✔
94
    if (Context::getContext().color()) bold = Color("bold");
2✔
95

96
    bool special = false;
2✔
97
    for (auto& i : unique) {
5✔
98
      // Highlight the special tags.
99
      special = (Context::getContext().color() && (i.first == "nocolor" || i.first == "nonag" ||
3✔
NEW
100
                                                   i.first == "nocal" || i.first == "next"))
×
101
                    ? true
3✔
102
                    : false;
103

104
      int row = view.addRow();
3✔
105
      view.set(row, 0, i.first, special ? bold : Color());
3✔
106
      view.set(row, 1, i.second, special ? bold : Color());
3✔
107
    }
108

109
    out << optionalBlankLine() << view.render() << optionalBlankLine();
2✔
110

111
    if (unique.size() == 1)
2✔
112
      Context::getContext().footnote("1 tag");
1✔
113
    else
114
      Context::getContext().footnote(format("{1} tags", unique.size()));
1✔
115

116
    if (quantity == 1)
2✔
117
      Context::getContext().footnote("(1 task)");
1✔
118
    else
119
      Context::getContext().footnote(format("({1} tasks)", quantity));
1✔
120

121
    out << '\n';
2✔
122
  } else {
2✔
NEW
123
    Context::getContext().footnote("No tags.");
×
UNCOV
124
    rc = 1;
×
125
  }
126

127
  output = out.str();
2✔
128
  return rc;
2✔
129
}
2✔
130

131
////////////////////////////////////////////////////////////////////////////////
132
CmdCompletionTags::CmdCompletionTags() {
4,389✔
133
  _keyword = "_tags";
4,389✔
134
  _usage = "task <filter> _tags";
4,389✔
135
  _description = "Shows only a list of all tags used, for autocompletion purposes";
4,389✔
136
  _read_only = true;
4,389✔
137
  _displays_id = false;
4,389✔
138
  _needs_gc = true;
4,389✔
139
  _uses_context = false;
4,389✔
140
  _accepts_filter = true;
4,389✔
141
  _accepts_modifications = false;
4,389✔
142
  _accepts_miscellaneous = false;
4,389✔
143
  _category = Command::Category::internal;
4,389✔
144
}
4,389✔
145

146
////////////////////////////////////////////////////////////////////////////////
147
int CmdCompletionTags::execute(std::string& output) {
1✔
148
  // Get all the tasks.
149
  auto tasks = Context::getContext().tdb2.pending_tasks();
1✔
150

151
  if (Context::getContext().config.getBoolean("complete.all.tags"))
1✔
NEW
152
    for (auto& task : Context::getContext().tdb2.completed_tasks()) tasks.push_back(task);
×
153

154
  // Apply filter.
155
  Filter filter;
1✔
156
  std::vector<Task> filtered;
1✔
157
  filter.subset(tasks, filtered);
1✔
158

159
  // Scan all the tasks for their tags, building a map using tag
160
  // names as keys.
161
  std::map<std::string, int> unique;
1✔
162
  for (auto& task : filtered)
11✔
163
    for (auto& tag : task.getTags()) unique[tag] = 0;
11✔
164

165
  // Add built-in tags to map.
166
  unique["nocolor"] = 0;
1✔
167
  unique["nonag"] = 0;
1✔
168
  unique["nocal"] = 0;
1✔
169
  unique["next"] = 0;
1✔
170
  unique["ACTIVE"] = 0;
1✔
171
  unique["ANNOTATED"] = 0;
1✔
172
  unique["BLOCKED"] = 0;
1✔
173
  unique["BLOCKING"] = 0;
1✔
174
  unique["CHILD"] = 0;  // 2017-01-07: Deprecated in 2.6.0
1✔
175
  unique["COMPLETED"] = 0;
1✔
176
  unique["DELETED"] = 0;
1✔
177
  unique["DUE"] = 0;
1✔
178
  unique["DUETODAY"] = 0;  // 2016-03-29: Deprecated in 2.6.0
1✔
179
  unique["INSTANCE"] = 0;
1✔
180
  unique["LATEST"] = 0;
1✔
181
  unique["MONTH"] = 0;
1✔
182
  unique["ORPHAN"] = 0;
1✔
183
  unique["OVERDUE"] = 0;
1✔
184
  unique["PARENT"] = 0;  // 2017-01-07: Deprecated in 2.6.0
1✔
185
  unique["PENDING"] = 0;
1✔
186
  unique["PRIORITY"] = 0;
1✔
187
  unique["PROJECT"] = 0;
1✔
188
  unique["QUARTER"] = 0;
1✔
189
  unique["READY"] = 0;
1✔
190
  unique["SCHEDULED"] = 0;
1✔
191
  unique["TAGGED"] = 0;
1✔
192
  unique["TEMPLATE"] = 0;
1✔
193
  unique["TODAY"] = 0;
1✔
194
  unique["TOMORROW"] = 0;
1✔
195
  unique["UDA"] = 0;
1✔
196
  unique["UNBLOCKED"] = 0;
1✔
197
  unique["UNTIL"] = 0;
1✔
198
  unique["WAITING"] = 0;
1✔
199
  unique["WEEK"] = 0;
1✔
200
  unique["YEAR"] = 0;
1✔
201
  unique["YESTERDAY"] = 0;
1✔
202

203
  // If you update the above list, update src/commands/CmdInfo.cpp and src/Task.cpp as well.
204

205
  std::stringstream out;
1✔
206
  for (auto& it : unique) out << it.first << '\n';
38✔
207

208
  output = out.str();
1✔
209
  return 0;
1✔
210
}
1✔
211

212
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc