• 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

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

37
#include <iostream>
38

39
////////////////////////////////////////////////////////////////////////////////
40
CmdDone::CmdDone() {
4,389✔
41
  _keyword = "done";
4,389✔
42
  _usage = "task <filter> done <mods>";
4,389✔
43
  _description = "Marks the specified task as completed";
4,389✔
44
  _read_only = false;
4,389✔
45
  _displays_id = false;
4,389✔
46
  _needs_gc = false;
4,389✔
47
  _uses_context = true;
4,389✔
48
  _accepts_filter = true;
4,389✔
49
  _accepts_modifications = true;
4,389✔
50
  _accepts_miscellaneous = false;
4,389✔
51
  _category = Command::Category::operation;
4,389✔
52
}
4,389✔
53

54
////////////////////////////////////////////////////////////////////////////////
55
int CmdDone::execute(std::string&) {
84✔
56
  auto rc = 0;
84✔
57
  auto count = 0;
84✔
58

59
  // Apply filter.
60
  Filter filter;
84✔
61
  std::vector<Task> filtered;
84✔
62
  filter.subset(filtered);
84✔
63
  if (filtered.size() == 0) {
84✔
NEW
64
    Context::getContext().footnote("No tasks specified.");
×
UNCOV
65
    return 1;
×
66
  }
67

68
  // Accumulated project change notifications.
69
  std::map<std::string, std::string> projectChanges;
84✔
70

71
  if (filtered.size() > 1) {
84✔
72
    feedback_affected("This command will alter {1} tasks.", filtered.size());
3✔
73
  }
74

75
  std::vector<Task> modified;
84✔
76
  for (auto& task : filtered) {
172✔
77
    Task before(task);
88✔
78

79
    if (task.getStatus() == Task::pending || task.getStatus() == Task::waiting) {
88✔
80
      // Complete the specified task.
81
      std::string question =
82
          format("Complete task {1} '{2}'?", task.identifier(true), task.get("description"));
174✔
83

84
      task.modify(Task::modAnnotate);
87✔
85
      task.setStatus(Task::completed);
87✔
86
      if (!task.has("end")) task.setAsNow("end");
87✔
87

88
      // Stop the task, if started.
89
      if (task.has("start")) {
87✔
90
        task.remove("start");
5✔
91
        if (Context::getContext().config.getBoolean("journal.time"))
5✔
NEW
92
          task.addAnnotation(Context::getContext().config.get("journal.time.stop.annotation"));
×
93
      }
94

95
      if (permission(before.diff(task) + question, filtered.size())) {
87✔
96
        updateRecurrenceMask(task);
87✔
97
        Context::getContext().tdb2.modify(task);
87✔
98
        ++count;
87✔
99
        feedback_affected("Completed task {1} '{2}'.", task);
87✔
100
        feedback_unblocked(task);
87✔
101
        dependencyChainOnComplete(task);
87✔
102
        if (Context::getContext().verbose("project"))
87✔
103
          projectChanges[task.get("project")] = onProjectChange(task);
87✔
104

105
        // Save unmodified task for potential nagging later
106
        modified.push_back(before);
87✔
107
      } else {
UNCOV
108
        std::cout << "Task not completed.\n";
×
109
        rc = 1;
×
NEW
110
        if (_permission_quit) break;
×
111
      }
112
    } else {
87✔
113
      std::cout << format("Task {1} '{2}' is neither pending nor waiting.", task.identifier(true),
2✔
114
                          task.get("description"))
2✔
115
                << '\n';
1✔
116
      rc = 1;
1✔
117
    }
118
  }
88✔
119

120
  nag(modified);
84✔
121

122
  // Now list the project changes.
123
  for (const auto& change : projectChanges)
167✔
124
    if (change.first != "") Context::getContext().footnote(change.second);
83✔
125

126
  feedback_affected(count == 1 ? "Completed {1} task." : "Completed {1} tasks.", count);
84✔
127
  return rc;
84✔
128
}
84✔
129

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