MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / execute

Method execute

src/commands/CmdUnique.cpp:55–90  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

53
54////////////////////////////////////////////////////////////////////////////////
55int CmdUnique::execute(std::string& output) {
56 // Apply filter.
57 Filter filter;
58 filter.disableSafety();
59 std::vector<Task> filtered;
60 filter.subset(filtered);
61
62 // Find <attribute>.
63 std::string attribute{};
64
65 // Just the first arg.
66 auto words = Context::getContext().cli2.getWords();
67 if (words.size() == 0) throw std::string("An attribute must be specified. See 'task _columns'.");
68 attribute = words[0];
69
70 std::string canonical;
71 if (!Context::getContext().cli2.canonicalize(canonical, "attribute", attribute))
72 throw std::string("You must specify an attribute or UDA.");
73
74 // Find the unique set of matching tasks.
75 std::set<std::string> values;
76 for (auto& task : filtered) {
77 if (task.has(canonical)) {
78 values.insert(task.get(canonical));
79 } else if (canonical == "id" && task.getStatus() != Task::deleted &&
80 task.getStatus() != Task::completed) {
81 values.insert(format(task.id));
82 }
83 }
84
85 // Generate list of values.
86 for (auto& value : values) output += value + '\n';
87
88 Context::getContext().headers.clear();
89 return 0;
90}
91
92///////////////////////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 8

disableSafetyMethod · 0.80
subsetMethod · 0.80
getWordsMethod · 0.80
canonicalizeMethod · 0.80
getStatusMethod · 0.80
clearMethod · 0.80
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected