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

Method execute

src/commands/CmdAdd.cpp:52–93  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

50
51////////////////////////////////////////////////////////////////////////////////
52int CmdAdd::execute(std::string& output) {
53 // Apply the command line modifications to the new task.
54 Task task;
55
56 // the task is empty, but DOM references can refer to earlier parts of the
57 // command line, e.g., `task add due:20110101 wait:due`.
58 task.modify(Task::modReplace, true);
59
60 // Validate a task for addition. This is stricter than `task.validate`, as any
61 // inconsistency is probably user error.
62 task.validate_add();
63
64 Context::getContext().tdb2.add(task);
65
66 // Do not display ID 0, users cannot query by that
67 auto status = task.getStatus();
68
69 // We may have a situation where both new-id and new-uuid config
70 // variables are set. In that case, we'll show the new-uuid, as
71 // it's enduring and never changes, and it's unlikely the caller
72 // asked for this if they just wanted a human-friendly number.
73
74 if (Context::getContext().verbose("new-uuid") && status == Task::recurring)
75 output += format("Created task {1} (recurrence template).\n", task.get("uuid"));
76
77 else if (Context::getContext().verbose("new-uuid") ||
78 (Context::getContext().verbose("new-id") &&
79 (status == Task::completed || status == Task::deleted)))
80 output += format("Created task {1}.\n", task.get("uuid"));
81
82 else if (Context::getContext().verbose("new-id") &&
83 (status == Task::pending || status == Task::waiting))
84 output += format("Created task {1}.\n", task.id);
85
86 else if (Context::getContext().verbose("new-id") && status == Task::recurring)
87 output += format("Created task {1} (recurrence template).\n", task.id);
88
89 if (Context::getContext().verbose("project"))
90 Context::getContext().footnote(onProjectChange(task));
91
92 return 0;
93}
94
95////////////////////////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 8

onProjectChangeFunction · 0.85
validate_addMethod · 0.80
getStatusMethod · 0.80
verboseMethod · 0.80
footnoteMethod · 0.80
modifyMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected