• 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.11
/src/commands/CmdHelp.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 <CmdHelp.h>
31
#include <Context.h>
32
#include <Table.h>
33
#include <format.h>
34
#include <shared.h>
35
#include <util.h>
36

37
#include <algorithm>
38

39
////////////////////////////////////////////////////////////////////////////////
40
CmdHelp::CmdHelp() {
4,389✔
41
  _keyword = "help";
4,389✔
42
  _usage = "task          help ['usage']";
4,389✔
43
  _description = "Displays this usage help text";
4,389✔
44
  _read_only = true;
4,389✔
45
  _displays_id = false;
4,389✔
46
  _needs_gc = false;
4,389✔
47
  _uses_context = false;
4,389✔
48
  _accepts_filter = false;
4,389✔
49
  _accepts_modifications = false;
4,389✔
50
  _accepts_miscellaneous = true;
4,389✔
51
  _category = Command::Category::misc;
4,389✔
52
}
4,389✔
53

54
////////////////////////////////////////////////////////////////////////////////
55
int CmdHelp::execute(std::string& output) {
1✔
56
  auto words = Context::getContext().cli2.getWords();
1✔
57
  if (words.size() == 1 && closeEnough("usage", words[0]))
1✔
NEW
58
    output = '\n' + composeUsage() + '\n';
×
59
  else
60
    output =
61
        '\n' + composeUsage() + '\n' +
2✔
62
        "Documentation for Taskwarrior can be found using 'man task', 'man taskrc', 'man "
63
        "task-color', 'man task-sync' or at https://taskwarrior.org\n"
64
        "\n"
65
        "The general form of commands is:\n"
66
        "  task [<filter>] <command> [<mods>]\n"
67
        "\n"
68
        "The <filter> consists of zero or more restrictions on which tasks to select, "
69
        "such as:\n"
70
        "  task                                      <command> <mods>\n"
71
        "  task 28                                   <command> <mods>\n"
72
        "  task +weekend                             <command> <mods>\n"
73
        "  task project:Home due.before:today        <command> <mods>\n"
74
        "  task ebeeab00-ccf8-464b-8b58-f7f2d606edfb <command> <mods>\n"
75
        "\n"
76
        "By default, filter elements are combined with an implicit 'and' operator, but "
77
        "'or' and 'xor' may also be used, provided parentheses are included:\n"
78
        "  task '(/[Cc]at|[Dd]og/ or /[0-9]+/)'      <command> <mods>\n"
79
        "\n"
80
        "A filter may target specific tasks using ID or UUID numbers.  To specify "
81
        "multiple tasks use one of these forms:\n"
82
        "  task 1,2,3                                    delete\n"
83
        "  task 1-3                                      info\n"
84
        "  task 1,2-5,19                                 modify pri:H\n"
85
        "  task 4-7 ebeeab00-ccf8-464b-8b58-f7f2d606edfb info\n"
86
        "\n"
87
        "The <mods> consist of zero or more changes to apply to the selected tasks, "
88
        "such as:\n"
89
        "  task <filter> <command> project:Home\n"
90
        "  task <filter> <command> +weekend +garden due:tomorrow\n"
91
        "  task <filter> <command> Description/annotation text\n"
92
        "  task <filter> <command> /from/to/     <- replace first match\n"
93
        "  task <filter> <command> /from/to/g    <- replace all matches\n"
94
        "\n"
95
        "Tags are arbitrary words, any quantity:\n"
96
        "  +tag       The + means add the tag\n"
97
        "  -tag       The - means remove the tag\n"
98
        "\n"
99
        "Built-in attributes are:\n"
100
        "  description:    Task description text\n"
101
        "  status:         Status of task - pending, completed, deleted, waiting\n"
102
        "  project:        Project name\n"
103
        "  priority:       Priority\n"
104
        "  due:            Due date\n"
105
        "  recur:          Recurrence frequency\n"
106
        "  until:          Expiration date of a task\n"
107
        "  limit:          Desired number of rows in report, or 'page'\n"
108
        "  wait:           Date until task becomes pending\n"
109
        "  entry:          Date task was created\n"
110
        "  end:            Date task was completed/deleted\n"
111
        "  start:          Date task was started\n"
112
        "  scheduled:      Date task is scheduled to start\n"
113
        "  modified:       Date task was last modified\n"
114
        "  depends:        Other tasks that this task depends upon\n"
115
        "\n"
116
        "Attribute modifiers make filters more precise.  Supported modifiers are:\n"
117
        "\n"
118
        "  Modifiers         Example            Equivalent           Meaning\n"
119
        "  ----------------  -----------------  -------------------  -------------------------\n"
120
        "                    due:today          due = today          Fuzzy match\n"
121
        "  not               due.not:today      due != today         Fuzzy non-match\n"
122
        "  before, below     due.before:today   due < today          Exact date comparison\n"
123
        "  after, above      due.after:today    due >= tomorrow      Exact date comparison\n"
124
        "  none              project.none:      project == ''        Empty\n"
125
        "  any               project.any:       project !== ''       Not empty\n"
126
        "  is, equals        project.is:x       project == x         Exact match\n"
127
        "  isnt              project.isnt:x     project !== x        Exact non-match\n"
128
        "  has, contains     desc.has:Hello     desc ~ Hello         Pattern match\n"
129
        "  hasnt,            desc.hasnt:Hello   desc !~ Hello        Pattern non-match\n"
130
        "  startswith, left  desc.left:Hel      desc ~ '^Hel'        Beginning match\n"
131
        "  endswith, right   desc.right:llo     desc ~ 'llo$'        End match\n"
132
        "  word              desc.word:Hello    desc ~ '\\bHello\\b'   Boundaried word match\n"
133
        "  noword            desc.noword:Hello  desc !~ '\\bHello\\b'  Boundaried word non-match\n"
134
        "\n"
135
        "Alternately algebraic expressions support:\n"
136
        "  and  or  xor            Logical operators\n"
137
        "  <  <=  =  !=  >=  >     Relational operators\n"
138
        "  (  )                    Precedence\n"
139
        "\n"
140
        "  task due.before:eom priority.not:L   list\n"
141
        "  task '(due < eom and priority != L)'  list\n"
142
        "\n"
143
        "The default .taskrc file can be overridden with:\n"
144
        "  task ... rc:<alternate file> ...\n"
145
        "  task ... rc:~/.alt_taskrc ...\n"
146
        "\n"
147
        "The values in .taskrc (or alternate) can be overridden with:\n"
148
        "  task ... rc.<name>=<value> ...\n"
149
        "  task rc.color=off list\n"
150
        "\n"
151
        "Any command or attribute name may be abbreviated if still unique:\n"
152
        "  task list project:Home\n"
153
        "  task li       pro:Home\n"
154
        "\n"
155
        "Some task descriptions need to be escaped because of the shell:\n"
156
        "  task add \"quoted ' quote\"\n"
157
        "  task add escaped \\' quote\n"
158
        "\n"
159
        "The argument -- tells Taskwarrior to treat all other args as description, even "
160
        "if they would otherwise be attributes or tags:\n"
161
        "  task add -- project:Home needs scheduling\n"
162
        "\n"
163
        "Many characters have special meaning to the shell, including:\n"
164
        "  $ ! ' \" ( ) ; \\ ` * ? { } [ ] < > | & % # ~\n"
165
        "\n";
1✔
166

167
  /*
168
    TODO To be included later, before the 'precedence' line.
169

170
    "  +  -                    Addition, Subtraktion\n" \
171
    "  !                       Negation\n" \
172
    "  ~  !~                   Treffer, kein Treffer\n" \
173
  */
174

175
  return 0;
1✔
176
}
1✔
177

178
////////////////////////////////////////////////////////////////////////////////
179
std::string CmdHelp::composeUsage() const {
1✔
180
  Table view;
1✔
181
  view.width(Context::getContext().getWidth());
1✔
182
  view.add("");
1✔
183
  view.add("");
1✔
184
  view.add("");
1✔
185

186
  // Static first row.
187
  auto row = view.addRow();
1✔
188
  view.set(row, 0, "Usage:");
1✔
189
  view.set(row, 1, "task");
1✔
190
  view.set(row, 2, "Runs rc.default.command, if specified.");
1✔
191

192
  // Obsolete method of getting a list of all commands.
193
  std::vector<std::string> all;
1✔
194
  for (auto& cmd : Context::getContext().commands) all.push_back(cmd.first);
92✔
195

196
  // Sort alphabetically by usage.
197
  std::sort(all.begin(), all.end());
1✔
198

199
  // Add the regular commands.
200
  for (auto& name : all) {
92✔
201
    if (name[0] != '_') {
91✔
202
      row = view.addRow();
72✔
203
      view.set(row, 1, Context::getContext().commands[name]->usage());
72✔
204
      view.set(row, 2, Context::getContext().commands[name]->description());
72✔
205
    }
206
  }
207

208
  // Add the helper commands.
209
  for (auto& name : all) {
92✔
210
    if (name[0] == '_') {
91✔
211
      row = view.addRow();
19✔
212
      view.set(row, 1, Context::getContext().commands[name]->usage());
19✔
213
      view.set(row, 2, Context::getContext().commands[name]->description());
19✔
214
    }
215
  }
216

217
  // Add the aliases commands.
218
  row = view.addRow();
1✔
219
  view.set(row, 1, " ");
1✔
220

221
  for (auto& alias : Context::getContext().config) {
251✔
222
    if (alias.first.substr(0, 6) == "alias.") {
250✔
223
      row = view.addRow();
4✔
224
      view.set(row, 1, alias.first.substr(6));
4✔
225
      view.set(row, 2, format("Aliased to '{1}'", alias.second));
4✔
226
    }
227
  }
228

229
  return view.render();
2✔
230
}
1✔
231

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