• 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.65
/src/commands/CmdDelete.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 <CmdDelete.h>
31
#include <Context.h>
32
#include <Filter.h>
33
#include <format.h>
34
#include <main.h>
35
#include <shared.h>
36

37
#include <iostream>
38

39
#define STRING_CMD_DELETE_TASK_R "Deleting recurring task {1} '{2}'."
40
#define STRING_CMD_DELETE_CONFIRM_R \
41
  "This is a recurring task.  Do you want to delete all pending recurrences of this same task?"
42

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

59
////////////////////////////////////////////////////////////////////////////////
60
int CmdDelete::execute(std::string&) {
72✔
61
  auto rc = 0;
72✔
62
  auto count = 0;
72✔
63

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

73
  // Accumulated project change notifications.
74
  std::map<std::string, std::string> projectChanges;
71✔
75

76
  if (filtered.size() > 1) {
71✔
77
    feedback_affected("This command will alter {1} tasks.", filtered.size());
13✔
78
  }
79
  for (auto& task : filtered) {
155✔
80
    Task before(task);
88✔
81

82
    if (task.getStatus() != Task::deleted) {
88✔
83
      // Delete the specified task.
84
      std::string question;
88✔
85
      question = format("Delete task {1} '{2}'?", task.identifier(true), task.get("description"));
88✔
86

87
      task.modify(Task::modAnnotate);
88✔
88
      task.setStatus(Task::deleted);
88✔
89
      if (!task.has("end")) task.setAsNow("end");
88✔
90

91
      if (permission(question, filtered.size())) {
88✔
92
        updateRecurrenceMask(task);
71✔
93
        ++count;
71✔
94
        Context::getContext().tdb2.modify(task);
71✔
95
        feedback_affected("Deleting task {1} '{2}'.", task);
71✔
96
        feedback_unblocked(task);
71✔
97
        dependencyChainOnComplete(task);
71✔
98
        if (Context::getContext().verbose("project"))
71✔
99
          projectChanges[task.get("project")] = onProjectChange(task);
69✔
100

101
        // Delete siblings.
102
        if (task.has("parent")) {
71✔
103
          if ((Context::getContext().config.get("recurrence.confirmation") == "prompt" &&
12✔
104
               confirm(STRING_CMD_DELETE_CONFIRM_R)) ||
21✔
105
              Context::getContext().config.getBoolean("recurrence.confirmation")) {
9✔
106
            std::vector<Task> siblings = Context::getContext().tdb2.siblings(task);
3✔
107
            for (auto& sibling : siblings) {
8✔
108
              sibling.modify(Task::modAnnotate);
5✔
109
              sibling.setStatus(Task::deleted);
5✔
110
              if (!sibling.has("end")) sibling.setAsNow("end");
5✔
111

112
              updateRecurrenceMask(sibling);
5✔
113
              Context::getContext().tdb2.modify(sibling);
5✔
114
              feedback_affected(STRING_CMD_DELETE_TASK_R, sibling);
5✔
115
              feedback_unblocked(sibling);
5✔
116
              ++count;
5✔
117
            }
118

119
            // Delete the parent
120
            Task parent;
3✔
121
            Context::getContext().tdb2.get(task.get("parent"), parent);
3✔
122
            parent.setStatus(Task::deleted);
3✔
123
            if (!parent.has("end")) parent.setAsNow("end");
3✔
124

125
            Context::getContext().tdb2.modify(parent);
3✔
126
          }
3✔
127
        }
128

129
        // Task potentially has child tasks - optionally delete them.
130
        else {
131
          std::vector<Task> children = Context::getContext().tdb2.children(task);
65✔
132
          if (children.size() &&
73✔
133
              ((Context::getContext().config.get("recurrence.confirmation") == "prompt" &&
69✔
134
                confirm(STRING_CMD_DELETE_CONFIRM_R)) ||
69✔
135
               Context::getContext().config.getBoolean("recurrence.confirmation"))) {
66✔
136
            for (auto& child : children) {
10✔
137
              child.modify(Task::modAnnotate);
7✔
138
              child.setStatus(Task::deleted);
7✔
139
              if (!child.has("end")) child.setAsNow("end");
7✔
140

141
              updateRecurrenceMask(child);
7✔
142
              Context::getContext().tdb2.modify(child);
7✔
143
              feedback_affected(STRING_CMD_DELETE_TASK_R, child);
7✔
144
              feedback_unblocked(child);
7✔
145
              ++count;
7✔
146
            }
147
          }
148
        }
65✔
149
      } else {
150
        std::cout << "Task not deleted.\n";
17✔
151
        rc = 1;
17✔
152
        if (_permission_quit) break;
17✔
153
      }
154
    } else {
88✔
NEW
155
      std::cout << format("Task {1} '{2}' is not deletable.", task.identifier(true),
×
NEW
156
                          task.get("description"))
×
NEW
157
                << '\n';
×
UNCOV
158
      rc = 1;
×
159
    }
160
  }
88✔
161

162
  // Now list the project changes.
163
  for (const auto& change : projectChanges)
128✔
164
    if (change.first != "") Context::getContext().footnote(change.second);
57✔
165

166
  feedback_affected(count == 1 ? "Deleted {1} task." : "Deleted {1} tasks.", count);
71✔
167

168
  return rc;
71✔
169
}
72✔
170

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