• 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

96.08
/src/commands/CmdUDAs.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 <CmdUDAs.h>
31
#include <Context.h>
32
#include <Filter.h>
33
#include <Table.h>
34
#include <Task.h>
35
#include <format.h>
36
#include <main.h>
37
#include <shared.h>
38
#include <util.h>
39

40
#include <algorithm>
41
#include <sstream>
42

43
////////////////////////////////////////////////////////////////////////////////
44
CmdUDAs::CmdUDAs() {
4,389✔
45
  _keyword = "udas";
4,389✔
46
  _usage = "task          udas";
4,389✔
47
  _description = "Shows all the defined UDA details";
4,389✔
48
  _read_only = true;
4,389✔
49
  _displays_id = false;
4,389✔
50
  _needs_gc = false;
4,389✔
51
  _uses_context = false;
4,389✔
52
  _accepts_filter = false;
4,389✔
53
  _accepts_modifications = false;
4,389✔
54
  _accepts_miscellaneous = false;
4,389✔
55
  _category = Command::Category::config;
4,389✔
56
}
4,389✔
57

58
////////////////////////////////////////////////////////////////////////////////
59
int CmdUDAs::execute(std::string& output) {
3✔
60
  int rc = 0;
3✔
61
  std::stringstream out;
3✔
62

63
  std::vector<std::string> udas;
3✔
64
  for (auto& name : Context::getContext().config) {
744✔
65
    if (name.first.substr(0, 4) == "uda." && name.first.find(".type") != std::string::npos) {
741✔
66
      auto period = name.first.find('.', 4);
4✔
67
      if (period != std::string::npos) udas.push_back(name.first.substr(4, period - 4));
4✔
68
    }
69
  }
70

71
  // Apply filter.
72
  Filter filter;
3✔
73
  std::vector<Task> filtered;
3✔
74
  filter.subset(filtered);
3✔
75

76
  if (udas.size()) {
3✔
77
    std::sort(udas.begin(), udas.end());
3✔
78

79
    // Render a list of UDA name, type, label, allowed values,
80
    // possible default value, and finally the usage count.
81
    Table table;
3✔
82
    table.width(Context::getContext().getWidth());
3✔
83
    table.add("Name");
3✔
84
    table.add("Type");
3✔
85
    table.add("Label");
3✔
86
    table.add("Allowed Values");
3✔
87
    table.add("Default");
3✔
88
    table.add("Usage Count");
3✔
89
    setHeaderUnderline(table);
3✔
90

91
    for (auto& uda : udas) {
7✔
92
      std::string type = Context::getContext().config.get("uda." + uda + ".type");
8✔
93
      std::string label = Context::getContext().config.get("uda." + uda + ".label");
8✔
94
      std::string values = Context::getContext().config.get("uda." + uda + ".values");
8✔
95
      std::string defval = Context::getContext().config.get("uda." + uda + ".default");
8✔
96
      if (label == "") label = uda;
4✔
97

98
      // Count UDA usage by UDA.
99
      int count = 0;
4✔
100
      for (auto& i : filtered)
9✔
101
        if (i.has(uda)) ++count;
5✔
102

103
      int row = table.addRow();
4✔
104
      table.set(row, 0, uda);
4✔
105
      table.set(row, 1, type);
4✔
106
      table.set(row, 2, label);
4✔
107
      table.set(row, 3, values);
4✔
108
      table.set(row, 4, defval);
4✔
109
      table.set(row, 5, count);
4✔
110
    }
4✔
111

NEW
112
    out << optionalBlankLine() << table.render() << optionalBlankLine()
×
113
        << (udas.size() == 1 ? format("{1} UDA defined", udas.size())
6✔
114
                             : format("{1} UDAs defined", udas.size()))
115
        << '\n';
6✔
116
  } else {
3✔
UNCOV
117
    out << "No UDAs defined.\n";
×
118
    rc = 1;
×
119
  }
120

121
  // Orphans are task attributes that are not represented in context.columns.
122
  std::map<std::string, int> orphans;
3✔
123
  for (auto& i : filtered) {
8✔
124
    for (auto& att : i.getUDAOrphans()) orphans[att]++;
7✔
125
  }
126

127
  if (orphans.size()) {
3✔
128
    // Display the orphans and their counts.
129
    Table orphanTable;
2✔
130
    orphanTable.width(Context::getContext().getWidth());
2✔
131
    orphanTable.add("Orphan UDA");
2✔
132
    orphanTable.add("Usage Count");
2✔
133
    setHeaderUnderline(orphanTable);
2✔
134

135
    for (auto& o : orphans) {
4✔
136
      int row = orphanTable.addRow();
2✔
137
      orphanTable.set(row, 0, o.first);
2✔
138
      orphanTable.set(row, 1, o.second);
2✔
139
    }
140

NEW
141
    out << optionalBlankLine() << orphanTable.render() << optionalBlankLine()
×
142
        << (udas.size() == 1 ? format("{1} Orphan UDA", orphans.size())
4✔
143
                             : format("{1} Orphan UDAs", orphans.size()))
144
        << '\n';
4✔
145
  }
2✔
146

147
  output = out.str();
3✔
148
  return rc;
3✔
149
}
3✔
150

151
///////////////////////////////////////////////////////////////////////////////
152
CmdCompletionUDAs::CmdCompletionUDAs() {
4,389✔
153
  _keyword = "_udas";
4,389✔
154
  _usage = "task          _udas";
4,389✔
155
  _description = "Shows the defined UDAs for completion purposes";
4,389✔
156
  _read_only = true;
4,389✔
157
  _displays_id = false;
4,389✔
158
  _needs_gc = false;
4,389✔
159
  _uses_context = false;
4,389✔
160
  _accepts_filter = false;
4,389✔
161
  _accepts_modifications = false;
4,389✔
162
  _accepts_miscellaneous = false;
4,389✔
163
  _category = Command::Category::internal;
4,389✔
164
}
4,389✔
165

166
////////////////////////////////////////////////////////////////////////////////
167
int CmdCompletionUDAs::execute(std::string& output) {
1✔
168
  std::vector<std::string> udas;
1✔
169
  for (auto& name : Context::getContext().config) {
252✔
170
    if (name.first.substr(0, 4) == "uda." && name.first.find(".type") != std::string::npos) {
251✔
171
      auto period = name.first.find('.', 4);
2✔
172
      if (period != std::string::npos) udas.push_back(name.first.substr(4, period - 4));
2✔
173
    }
174
  }
175

176
  if (udas.size()) {
1✔
177
    std::sort(udas.begin(), udas.end());
1✔
178
    output = join("\n", udas) + '\n';
1✔
179
  }
180

181
  return 0;
1✔
182
}
1✔
183

184
///////////////////////////////////////////////////////////////////////////////
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

© 2026 Coveralls, Inc