• 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

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

37
////////////////////////////////////////////////////////////////////////////////
38
CmdExport::CmdExport() {
4,389✔
39
  _keyword = "export";
4,389✔
40
  _usage = "task <filter> export [<report>]";
4,389✔
41
  _description = "Exports tasks in JSON format";
4,389✔
42
  _read_only = true;
4,389✔
43
  _displays_id = true;
4,389✔
44
  _needs_gc = true;
4,389✔
45
  _uses_context = false;
4,389✔
46
  _accepts_filter = true;
4,389✔
47
  _accepts_modifications = false;
4,389✔
48
  _accepts_miscellaneous = true;
4,389✔
49
  _category = Command::Category::migration;
4,389✔
50
}
4,389✔
51

52
////////////////////////////////////////////////////////////////////////////////
53
int CmdExport::execute(std::string& output) {
99✔
54
  int rc = 0;
99✔
55

56
  auto words = Context::getContext().cli2.getWords();
99✔
57
  std::string selectedReport = "";
99✔
58

59
  if (words.size() == 1) {
99✔
60
    // Find the report matching the prompt
61
    for (auto& command : Context::getContext().commands) {
47✔
62
      if (command.second->category() == Command::Category::report &&
53✔
63
          closeEnough(command.second->keyword(), words[0])) {
53✔
64
        selectedReport = command.second->keyword();
1✔
65
        break;
1✔
66
      }
67
    }
68

69
    if (selectedReport.empty()) {
1✔
NEW
70
      throw format("Unable to find report that matches '{1}'.", words[0]);
×
71
    }
72
  }
73

74
  auto reportSort = Context::getContext().config.get("report." + selectedReport + ".sort");
198✔
75
  auto reportFilter = Context::getContext().config.get("report." + selectedReport + ".filter");
198✔
76

77
  auto sortOrder = split(reportSort, ',');
99✔
78
  if (sortOrder.size() != 0 && sortOrder[0] != "none") {
99✔
79
    validateSortColumns(sortOrder);
1✔
80
  }
81

82
  // Add the report filter to any existing filter.
83
  if (reportFilter != "") Context::getContext().cli2.addFilter(reportFilter);
99✔
84

85
  // Make sure reccurent tasks are generated.
86
  handleUntil();
99✔
87
  handleRecurrence();
99✔
88

89
  // Apply filter.
90
  Filter filter;
99✔
91
  std::vector<Task> filtered;
99✔
92
  filter.subset(filtered);
99✔
93

94
  std::vector<int> sequence;
99✔
95
  if (sortOrder.size() && sortOrder[0] == "none") {
99✔
96
    // Assemble a sequence vector that represents the tasks listed in
97
    // Context::getContext ().cli2._uuid_ranges, in the order in which they appear. This
98
    // equates to no sorting, just a specified order.
NEW
99
    sortOrder.clear();
×
NEW
100
    for (auto& i : Context::getContext().cli2._uuid_list)
×
NEW
101
      for (unsigned int t = 0; t < filtered.size(); ++t)
×
NEW
102
        if (filtered[t].get("uuid") == i) sequence.push_back(t);
×
103
  } else {
104
    // sort_tasks requires the order array initially be identity
105
    for (unsigned int i = 0; i < filtered.size(); ++i) sequence.push_back(i);
275✔
106

107
    // if no sort order, sort by id
108
    if (!sortOrder.size()) {
99✔
109
      reportSort = "id,uuid";
98✔
110
    }
111

112
    // Sort the tasks.
113
    sort_tasks(filtered, sequence, reportSort);
99✔
114
  }
115

116
  // Export == render.
117
  Timer timer;
99✔
118

119
  // Obey 'limit:N'.
120
  int rows = 0;
99✔
121
  int lines = 0;
99✔
122
  Context::getContext().getLimits(rows, lines);
99✔
123
  int limit = (rows > lines ? rows : lines);
99✔
124

125
  // Is output contained within a JSON array?
126
  bool json_array = Context::getContext().config.getBoolean("json.array");
99✔
127

128
  // Compose output.
129
  if (json_array) output += "[\n";
99✔
130

131
  int counter = 0;
99✔
132
  for (auto& t : sequence) {
271✔
133
    auto task = filtered[t];
174✔
134
    if (counter) {
174✔
135
      if (json_array) output += ',';
75✔
136
      output += '\n';
75✔
137
    }
138

139
    output += task.composeJSON(true);
174✔
140

141
    ++counter;
174✔
142
    if (limit && counter >= limit) break;
174✔
143
  }
174✔
144

145
  if (filtered.size()) output += '\n';
99✔
146

147
  if (json_array) output += "]\n";
99✔
148

149
  Context::getContext().time_render_us += timer.total_us();
99✔
150
  return rc;
99✔
151
}
99✔
152

153
////////////////////////////////////////////////////////////////////////////////
154

155
void CmdExport::validateSortColumns(std::vector<std::string>& columns) {
1✔
156
  for (auto& col : columns) legacySortColumnMap(col);
2✔
157
}
1✔
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