• 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

98.02
/src/commands/CmdCommands.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 <CmdCommands.h>
31
#include <Command.h>
32
#include <Context.h>
33
#include <Table.h>
34
#include <stdlib.h>
35
#include <util.h>
36

37
#include <algorithm>
38
#include <sstream>
39

40
////////////////////////////////////////////////////////////////////////////////
41
CmdCommands::CmdCommands() {
4,389✔
42
  _keyword = "commands";
4,389✔
43
  _usage = "task          commands";
4,389✔
44
  _description = "Generates a list of all commands, with behavior details";
4,389✔
45
  _read_only = true;
4,389✔
46
  _displays_id = false;
4,389✔
47
  _needs_gc = false;
4,389✔
48
  _uses_context = false;
4,389✔
49
  _accepts_filter = false;
4,389✔
50
  _accepts_modifications = false;
4,389✔
51
  _accepts_miscellaneous = false;
4,389✔
52
  _category = Command::Category::metadata;
4,389✔
53
}
4,389✔
54

55
////////////////////////////////////////////////////////////////////////////////
56
int CmdCommands::execute(std::string& output) {
2✔
57
  Table view;
2✔
58
  view.width(Context::getContext().getWidth());
2✔
59
  view.add("Command");
2✔
60
  view.add("Category");
2✔
61
  view.add("R/W", false);
2✔
62
  view.add("ID", false);
2✔
63
  view.add("GC", false);
2✔
64
  view.add("Context", false);
2✔
65
  view.add("Filter", false);
2✔
66
  view.add("Mods", false);
2✔
67
  view.add("Misc", false);
2✔
68
  view.add("Description");
2✔
69
  view.leftMargin(Context::getContext().config.getInteger("indent.report"));
2✔
70
  view.extraPadding(Context::getContext().config.getInteger("row.padding"));
2✔
71
  view.intraPadding(Context::getContext().config.getInteger("column.padding"));
2✔
72
  setHeaderUnderline(view);
2✔
73

74
  for (auto& command : Context::getContext().commands) {
182✔
75
    auto row = view.addRow();
180✔
76
    view.set(row, 0, command.first);
180✔
77
    view.set(row, 1, Command::categoryNames.at(command.second->category()));
180✔
78

79
    if (command.second->read_only())
180✔
80
      view.set(row, 2, "RO");
146✔
81
    else
82
      view.set(row, 2, "RW");
34✔
83

84
    if (command.second->displays_id()) view.set(row, 3, "ID");
180✔
85

86
    if (command.second->needs_gc()) view.set(row, 4, "GC");
180✔
87

88
    if (command.second->uses_context()) view.set(row, 5, "Ctxt");
180✔
89

90
    if (command.second->accepts_filter()) view.set(row, 6, "Filt");
180✔
91

92
    if (command.second->accepts_modifications()) view.set(row, 7, "Mods");
180✔
93

94
    if (command.second->accepts_miscellaneous()) view.set(row, 8, "Misc");
180✔
95

96
    view.set(row, 9, command.second->description());
180✔
97
  }
98

99
  output = optionalBlankLine() + view.render() + optionalBlankLine() + '\n';
2✔
100

101
  return 0;
2✔
102
}
2✔
103

104
////////////////////////////////////////////////////////////////////////////////
105
CmdCompletionCommands::CmdCompletionCommands() {
4,389✔
106
  _keyword = "_commands";
4,389✔
107
  _usage = "task          _commands";
4,389✔
108
  _description = "Generates a list of all commands, for autocompletion purposes";
4,389✔
109
  _read_only = true;
4,389✔
110
  _displays_id = false;
4,389✔
111
  _needs_gc = false;
4,389✔
112
  _uses_context = false;
4,389✔
113
  _accepts_filter = false;
4,389✔
114
  _accepts_modifications = false;
4,389✔
115
  _accepts_miscellaneous = false;
4,389✔
116
  _category = Command::Category::internal;
4,389✔
117
}
4,389✔
118

119
////////////////////////////////////////////////////////////////////////////////
120
int CmdCompletionCommands::execute(std::string& output) {
8✔
121
  // Get a list of all commands.
122
  std::vector<std::string> commands;
8✔
123
  for (const auto& command : Context::getContext().commands) commands.push_back(command.first);
728✔
124

125
  // Sort alphabetically.
126
  std::sort(commands.begin(), commands.end());
8✔
127

128
  std::stringstream out;
8✔
129
  for (const auto& c : commands) out << c << '\n';
728✔
130

131
  output = out.str();
8✔
132
  return 0;
8✔
133
}
8✔
134

135
////////////////////////////////////////////////////////////////////////////////
136
CmdZshCommands::CmdZshCommands() {
4,389✔
137
  _keyword = "_zshcommands";
4,389✔
138
  _usage = "task          _zshcommands";
4,389✔
139
  _description = "Generates a list of all commands, for zsh autocompletion purposes";
4,389✔
140
  _read_only = true;
4,389✔
141
  _displays_id = false;
4,389✔
142
  _needs_gc = false;
4,389✔
143
  _uses_context = false;
4,389✔
144
  _accepts_filter = false;
4,389✔
145
  _accepts_modifications = false;
4,389✔
146
  _accepts_miscellaneous = false;
4,389✔
147
  _category = Command::Category::internal;
4,389✔
148
}
4,389✔
149

150
////////////////////////////////////////////////////////////////////////////////
151
struct ZshCommand {
152
  bool operator<(const struct ZshCommand&) const;
153

154
  Command::Category _category;
155
  std::string _command;
156
  std::string _description;
157
};
158

159
////////////////////////////////////////////////////////////////////////////////
160
bool ZshCommand::operator<(const struct ZshCommand& other) const {
1,445✔
161
  // Lexicographical comparison.
162
  if (_category != other._category) return (_category < other._category);
1,445✔
163

164
  if (_command != other._command) return (_command < other._command);
816✔
165

NEW
166
  if (_description != other._description) return (_description < other._description);
×
167

168
  return false;
×
169
}
170

171
////////////////////////////////////////////////////////////////////////////////
172
int CmdZshCommands::execute(std::string& output) {
2✔
173
  // Get a list of all command descriptions, sorted by category and then
174
  // alphabetically by command name.
175

176
  // Since not all supported compilers support tuples, we use a least common
177
  // denominator alternative: a custom struct type.
178

179
  std::vector<ZshCommand> commands;
2✔
180
  for (auto& command : Context::getContext().commands) {
183✔
181
    ZshCommand zshCommand{command.second->category(), command.first, command.second->description()};
181✔
182
    commands.push_back(zshCommand);
181✔
183
  }
181✔
184

185
  std::sort(commands.begin(), commands.end());
2✔
186

187
  // Emit the commands in order.
188
  std::stringstream out;
2✔
189
  for (const auto& zc : commands)
183✔
190
    out << zc._command << ':' << Command::categoryNames.at(zc._category) << ':' << zc._description
724✔
191
        << '\n';
181✔
192

193
  output = out.str();
2✔
194
  return 0;
2✔
195
}
2✔
196

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