///////////////////////////////////////////////////////////////////////////
| 53 | |
| 54 | //////////////////////////////////////////////////////////////////////////////// |
| 55 | int 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 | /////////////////////////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected