• 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

94.59
/src/commands/CmdDenotate.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 <CmdDenotate.h>
31
#include <Context.h>
32
#include <Filter.h>
33
#include <format.h>
34
#include <main.h>
35
#include <shared.h>
36
#include <util.h>
37

38
#include <iostream>
39

40
#define STRING_CMD_DENO_NO "Task not denotated."
41
#define STRING_CMD_DENO_1 "Denotated {1} task."
42
#define STRING_CMD_DENO_N "Denotated {1} tasks."
43

44
////////////////////////////////////////////////////////////////////////////////
45
CmdDenotate::CmdDenotate() {
4,389✔
46
  _keyword = "denotate";
4,389✔
47
  _usage = "task <filter> denotate <pattern>";
4,389✔
48
  _description = "Deletes an annotation";
4,389✔
49
  _read_only = false;
4,389✔
50
  _displays_id = false;
4,389✔
51
  _needs_gc = false;
4,389✔
52
  _uses_context = true;
4,389✔
53
  _accepts_filter = true;
4,389✔
54
  _accepts_modifications = false;
4,389✔
55
  _accepts_miscellaneous = true;
4,389✔
56
  _category = Command::Category::operation;
4,389✔
57
}
4,389✔
58

59
////////////////////////////////////////////////////////////////////////////////
60
int CmdDenotate::execute(std::string&) {
9✔
61
  auto rc = 0;
9✔
62
  auto count = 0;
9✔
63
  auto sensitive = Context::getContext().config.getBoolean("search.case.sensitive");
9✔
64

65
  // Apply filter.
66
  Filter filter;
9✔
67
  std::vector<Task> filtered;
9✔
68
  filter.subset(filtered);
9✔
69
  if (filtered.size() == 0) {
9✔
70
    Context::getContext().footnote("No tasks specified.");
1✔
71
    return 1;
1✔
72
  }
73

74
  // Extract all the ORIGINAL MODIFICATION args as simple text patterns.
75
  std::string pattern = "";
8✔
76
  for (auto& a : Context::getContext().cli2._args) {
102✔
77
    if (a.hasTag("MISCELLANEOUS")) {
94✔
78
      if (pattern != "") pattern += ' ';
5✔
79

80
      pattern += a.attribute("raw");
5✔
81
    }
82
  }
83

84
  // Accumulated project change notifications.
85
  std::map<std::string, std::string> projectChanges;
8✔
86

87
  if (filtered.size() > 1) {
8✔
88
    feedback_affected("This command will alter {1} tasks.", filtered.size());
×
89
  }
90
  for (auto& task : filtered) {
15✔
91
    Task before(task);
8✔
92

93
    auto annotations = task.getAnnotations();
8✔
94

95
    if (annotations.size() == 0)
8✔
96
      throw std::string("The specified task has no annotations that can be deleted.");
1✔
97

98
    std::string anno;
7✔
99
    auto match = false;
7✔
100
    for (auto i = annotations.begin(); i != annotations.end(); ++i) {
15✔
101
      if (i->second == pattern) {
11✔
102
        match = true;
3✔
103
        anno = i->second;
3✔
104
        annotations.erase(i);
3✔
105
        task.setAnnotations(annotations);
3✔
106
        break;
3✔
107
      }
108
    }
109

110
    if (!match) {
7✔
111
      for (auto i = annotations.begin(); i != annotations.end(); ++i) {
8✔
112
        auto loc = find(i->second, pattern, sensitive);
7✔
113
        if (loc != std::string::npos) {
7✔
114
          anno = i->second;
3✔
115
          annotations.erase(i);
3✔
116
          task.setAnnotations(annotations);
3✔
117
          break;
3✔
118
        }
119
      }
120
    }
121

122
    if (before.getAnnotations() != task.getAnnotations()) {
7✔
123
      auto question =
124
          format("Denotate task {1} '{2}'?", task.identifier(true), task.get("description"));
12✔
125

126
      if (permission(before.diff(task) + question, filtered.size())) {
6✔
127
        ++count;
6✔
128
        Context::getContext().tdb2.modify(task);
6✔
129
        feedback_affected(format("Found annotation '{1}' and deleted it.", anno));
6✔
130
        if (Context::getContext().verbose("project"))
6✔
131
          projectChanges[task.get("project")] = onProjectChange(task, false);
6✔
132
      } else {
133
        std::cout << STRING_CMD_DENO_NO << '\n';
×
134
        rc = 1;
×
NEW
135
        if (_permission_quit) break;
×
136
      }
137
    } else {
6✔
138
      std::cout << format("Did not find any matching annotation to be deleted for '{1}'.\n",
2✔
139
                          pattern);
1✔
140
      rc = 1;
1✔
141
    }
142
  }
9✔
143

144
  // Now list the project changes.
145
  for (const auto& change : projectChanges)
13✔
146
    if (change.first != "") Context::getContext().footnote(change.second);
6✔
147

148
  feedback_affected(count == 1 ? STRING_CMD_DENO_1 : STRING_CMD_DENO_N, count);
7✔
149
  return rc;
7✔
150
}
11✔
151

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