mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
TW-1704: Task: Use Task::identifier to reference the task
To achieve consistent output, use a helper method to generate a proper handle - ID for tasks with non-zero ID, UUID otherwise.
This commit is contained in:
parent
1236abc7d5
commit
2d25cf6f59
16 changed files with 50 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
2.5.1 () -
|
||||
|
||||
- TW-1704 Use Task::identifier to reference the Task in the output
|
||||
- The default configuration is now 256-color only.
|
||||
- The 'columns' report now shows whether a column is modifiable or read only.
|
||||
|
||||
|
|
14
src/Task.cpp
14
src/Task.cpp
|
@ -202,6 +202,20 @@ std::string Task::statusToText (Task::status s)
|
|||
return "pending";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Returns a proper handle to the task. Tasks should not be referenced by UUIDs
|
||||
// as long as they have non-zero ID.
|
||||
//
|
||||
const std::string Task::identifier (bool shortened /* = false */) const
|
||||
{
|
||||
if (this->id != 0)
|
||||
return format (this->id);
|
||||
else if (shortened)
|
||||
return this->get ("uuid").substr (0, 8);
|
||||
else
|
||||
return this->get ("uuid");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::setAsNow (const std::string& att)
|
||||
{
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
void setAsNow (const std::string&);
|
||||
bool has (const std::string&) const;
|
||||
std::vector <std::string> all ();
|
||||
const std::string identifier (bool shortened = false) const;
|
||||
const std::string get (const std::string&) const;
|
||||
const std::string& get_ref (const std::string&) const;
|
||||
int get_int (const std::string&) const;
|
||||
|
|
|
@ -79,7 +79,7 @@ int CmdAnnotate::execute (std::string&)
|
|||
|
||||
// Annotate the specified task.
|
||||
std::string question = format (STRING_CMD_ANNO_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modAnnotate, true);
|
||||
|
|
|
@ -79,7 +79,7 @@ int CmdAppend::execute (std::string&)
|
|||
|
||||
// Append to the specified task.
|
||||
std::string question = format (STRING_CMD_APPEND_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modAppend, true);
|
||||
|
|
|
@ -80,13 +80,8 @@ int CmdDelete::execute (std::string&)
|
|||
{
|
||||
// Delete the specified task.
|
||||
std::string question;
|
||||
if (task.id)
|
||||
question = format (STRING_CMD_DELETE_CONFIRM,
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
else
|
||||
question = format (STRING_CMD_DELETE_CONFIRM,
|
||||
task.get ("uuid"),
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modAnnotate);
|
||||
|
@ -173,7 +168,7 @@ int CmdDelete::execute (std::string&)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_DELETE_NOT_DEL,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
|
|
|
@ -127,7 +127,7 @@ int CmdDenotate::execute (std::string&)
|
|||
if (before != task)
|
||||
{
|
||||
std::string question = format (STRING_CMD_DENO_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
if (permission (taskDifferences (before, task) + question, filtered.size ()))
|
||||
|
|
|
@ -81,7 +81,7 @@ int CmdDone::execute (std::string&)
|
|||
{
|
||||
// Complete the specified task.
|
||||
std::string question = format (STRING_CMD_DONE_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modAnnotate);
|
||||
|
@ -121,7 +121,7 @@ int CmdDone::execute (std::string&)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_DONE_NOTPEND,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
|
|
|
@ -88,7 +88,7 @@ int CmdDuplicate::execute (std::string&)
|
|||
dup.remove ("recur");
|
||||
dup.remove ("until");
|
||||
dup.remove ("imask");
|
||||
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.id)
|
||||
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.identifier ())
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ int CmdDuplicate::execute (std::string&)
|
|||
else if (dup.getStatus () == Task::recurring)
|
||||
{
|
||||
dup.remove ("mask");
|
||||
std::cout << format (STRING_CMD_DUPLICATE_REC, task.id)
|
||||
std::cout << format (STRING_CMD_DUPLICATE_REC, task.identifier ())
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ int CmdDuplicate::execute (std::string&)
|
|||
dup.modify (Task::modAnnotate);
|
||||
|
||||
if (permission (format (STRING_CMD_DUPLICATE_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description")),
|
||||
filtered.size ()))
|
||||
{
|
||||
|
|
|
@ -82,13 +82,8 @@ int CmdModify::execute (std::string&)
|
|||
checkConsistency(before, task);
|
||||
|
||||
std::string question;
|
||||
if (task.id != 0)
|
||||
question = format (STRING_CMD_MODIFY_CONFIRM,
|
||||
task.id,
|
||||
task.get ("description"));
|
||||
else
|
||||
question = format (STRING_CMD_MODIFY_CONFIRM,
|
||||
task.get ("uuid"),
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
if (permission (taskDifferences (before, task) + question, filtered.size ()))
|
||||
|
|
|
@ -79,7 +79,7 @@ int CmdPrepend::execute (std::string&)
|
|||
|
||||
// Prepend to the specified task.
|
||||
std::string question = format (STRING_CMD_PREPEND_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modPrepend, true);
|
||||
|
|
|
@ -80,7 +80,7 @@ int CmdStart::execute (std::string&)
|
|||
|
||||
// Start the specified task.
|
||||
std::string question = format (STRING_CMD_START_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
task.modify (Task::modAnnotate);
|
||||
task.setAsNow ("start");
|
||||
|
|
|
@ -78,7 +78,7 @@ int CmdStop::execute (std::string&)
|
|||
|
||||
// Stop the specified task.
|
||||
std::string question = format (STRING_CMD_STOP_CONFIRM,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
task.modify (Task::modAnnotate);
|
||||
|
@ -108,7 +108,7 @@ int CmdStop::execute (std::string&)
|
|||
else
|
||||
{
|
||||
std::cout << format (STRING_CMD_STOP_ALREADY,
|
||||
task.id,
|
||||
task.identifier (true),
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
rc = 1;
|
||||
|
|
|
@ -69,21 +69,12 @@ int CmdUrgency::execute (std::string& output)
|
|||
// Display urgency for the selected tasks.
|
||||
std::stringstream out;
|
||||
for (auto& task : filtered)
|
||||
{
|
||||
if (task.id)
|
||||
{
|
||||
out << format (STRING_CMD_URGENCY_RESULT,
|
||||
task.id, trim (format (task.urgency (), 6, 3)))
|
||||
<< "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << format (STRING_CMD_URGENCY_RESULT,
|
||||
task.get ("uuid"),
|
||||
task.identifier (),
|
||||
trim (format (task.urgency (), 6, 3)))
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
output = out.str ();
|
||||
return 0;
|
||||
|
|
|
@ -145,7 +145,7 @@ void dependencyChainOnComplete (Task& task)
|
|||
// Nag about broken chain.
|
||||
if (context.config.getBoolean ("dependency.reminder"))
|
||||
{
|
||||
std::cout << format (STRING_DEPEND_BLOCKED, task.id)
|
||||
std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ())
|
||||
<< "\n";
|
||||
|
||||
for (auto& b : blocking)
|
||||
|
@ -200,7 +200,7 @@ void dependencyChainOnStart (Task& task)
|
|||
// broken chain.
|
||||
if (blocking.size ())
|
||||
{
|
||||
std::cout << format (STRING_DEPEND_BLOCKED, task.id)
|
||||
std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ())
|
||||
<< "\n";
|
||||
|
||||
for (auto& b : blocking)
|
||||
|
|
|
@ -309,11 +309,9 @@ void feedback_affected (const std::string& effect, const Task& task)
|
|||
{
|
||||
if (context.verbose ("affected"))
|
||||
{
|
||||
if (task.id)
|
||||
std::cout << format (effect, task.id, task.get ("description"))
|
||||
<< "\n";
|
||||
else
|
||||
std::cout << format (effect, task.get ("uuid"), task.get ("description"))
|
||||
std::cout << format (effect,
|
||||
task.identifier (true),
|
||||
task.get ("description"))
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
@ -373,11 +371,7 @@ void feedback_special_tags (const Task& task, const std::string& tag)
|
|||
|
||||
if (msg.length ())
|
||||
{
|
||||
if (task.id)
|
||||
std::cout << format (msg, task.id)
|
||||
<< "\n";
|
||||
else
|
||||
std::cout << format (msg, task.get ("uuid"))
|
||||
std::cout << format (msg, task.identifier ())
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
@ -506,7 +500,9 @@ std::string onExpiration (Task& task)
|
|||
std::stringstream msg;
|
||||
|
||||
if (context.verbose ("affected"))
|
||||
msg << format (STRING_FEEDBACK_EXPIRED, task.id, task.get ("description"));
|
||||
msg << format (STRING_FEEDBACK_EXPIRED,
|
||||
task.identifier (true),
|
||||
task.get ("description"));
|
||||
|
||||
return msg.str ();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue