mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
DOM: Clarified _get behavior
- It is an error to provide no DOM references (task _get). - It is an error to provide bad DOM references (task _get donkey). In this example, 'donkey' could be a UDA orphan. - It is not an error for a valid DOM reference to yield no value.
This commit is contained in:
parent
ebecaf420e
commit
37bd07883b
11 changed files with 47 additions and 16 deletions
|
@ -51,30 +51,47 @@ CmdGet::CmdGet ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Rely on the Lexer to correctly identify DOM references, then jsut iterate
|
||||
// over those.
|
||||
//
|
||||
// It is an error to specify no DOM references.
|
||||
// It is not an error for a DOM reference to resolve to a blank value.
|
||||
int CmdGet::execute (std::string& output)
|
||||
{
|
||||
// Obtain the arguments from the description. That way, things like '--'
|
||||
// have already been handled.
|
||||
std::vector <std::string> words = context.cli2.getWords (false);
|
||||
if (words.size () == 0)
|
||||
throw std::string (STRING_CMD_GET_NO_DOM);
|
||||
|
||||
bool found = false;
|
||||
std::vector <std::string> results;
|
||||
for (auto& word : words)
|
||||
for (auto& arg : context.cli2._args)
|
||||
{
|
||||
Task t;
|
||||
Variant result;
|
||||
if (context.dom.get (word, t, result))
|
||||
switch (arg._lextype)
|
||||
{
|
||||
results.push_back ((std::string) result);
|
||||
found = true;
|
||||
case Lexer::Type::dom:
|
||||
{
|
||||
Task t;
|
||||
Variant result;
|
||||
if (context.dom.get (arg.attribute ("raw"), t, result))
|
||||
results.push_back ((std::string) result);
|
||||
else
|
||||
results.push_back ("");
|
||||
}
|
||||
break;
|
||||
|
||||
// Look for non-refs to complain about.
|
||||
case Lexer::Type::word:
|
||||
case Lexer::Type::identifier:
|
||||
if (! arg.hasTag ("BINARY") &&
|
||||
! arg.hasTag ("CMD"))
|
||||
throw format (STRING_CMD_GET_BAD_REF, arg.attribute ("raw"));
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (results.size () == 0)
|
||||
throw std::string (STRING_CMD_GET_NO_DOM);
|
||||
|
||||
join (output, " ", results);
|
||||
output += "\n";
|
||||
return found ? 0 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Zählt gewählte Aufgaben"
|
||||
#define STRING_CMD_GET_USAGE "DOM-Accessor"
|
||||
#define STRING_CMD_GET_NO_DOM "Keine DOM-Referenz spezifiziert."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Keine UDAs festgelegt."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA festgelegt"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Counts matching tasks"
|
||||
#define STRING_CMD_GET_USAGE "DOM Accessor"
|
||||
#define STRING_CMD_GET_NO_DOM "No DOM reference specified."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "No UDAs defined."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA defined"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Nombras kongruantajn taskojn"
|
||||
#define STRING_CMD_GET_USAGE "DOM-enirilo"
|
||||
#define STRING_CMD_GET_NO_DOM "Nenia DOM-referenco specifata."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Nenia UDA definita."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA definita"
|
||||
|
|
|
@ -373,6 +373,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Cuenta tareas que coinciden"
|
||||
#define STRING_CMD_GET_USAGE "Método de acceso al DOM"
|
||||
#define STRING_CMD_GET_NO_DOM "Referencia a DOM no especificada."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Ningún UDA definido."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA definido"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Compte les taches correspondantes"
|
||||
#define STRING_CMD_GET_USAGE "Accesseur au DOM"
|
||||
#define STRING_CMD_GET_NO_DOM "Aucune référence de DOM spécifié."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Aucuns ADUs définies."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} ADU définie"
|
||||
|
|
|
@ -365,6 +365,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Conteggia task corrispondenti"
|
||||
#define STRING_CMD_GET_USAGE "DOM Accessor"
|
||||
#define STRING_CMD_GET_NO_DOM "No DOM reference specified."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Nessun UDA definito."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA definito"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "一致した タスク をカウント"
|
||||
#define STRING_CMD_GET_USAGE "DOM Accessor"
|
||||
#define STRING_CMD_GET_NO_DOM "No DOM reference specified."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "UDAが一つも定義されていません。"
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA が定義されました。"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Zlicza pasujące zadania"
|
||||
#define STRING_CMD_GET_USAGE "DOM Akcesor"
|
||||
#define STRING_CMD_GET_NO_DOM "Brak zdefiniowanej referencji do DOM."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Nie zdefiniowano UDA"
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} zdefiniowane UDA"
|
||||
|
|
|
@ -366,6 +366,7 @@
|
|||
#define STRING_CMD_COUNT_USAGE "Conta tarefas correspondentes"
|
||||
#define STRING_CMD_GET_USAGE "Método de acesso ao DOM"
|
||||
#define STRING_CMD_GET_NO_DOM "Referência DOM não especificada."
|
||||
#define STRING_CMD_GET_BAD_REF "'{1}' is not a DOM reference."
|
||||
|
||||
#define STRING_CMD_UDAS_NO "Nenhum UDA definido."
|
||||
#define STRING_CMD_UDAS_SUMMARY "{1} UDA definido"
|
||||
|
|
|
@ -50,6 +50,11 @@ class TestDOM(TestCase):
|
|||
code, out, err = self.t.runError("_get")
|
||||
self.assertEqual("No DOM reference specified.\n", err)
|
||||
|
||||
def test_dom_bad_ref(self):
|
||||
""" DOM bad reference """
|
||||
code, out, err = self.t.runError("_get donkey")
|
||||
self.assertEqual("'donkey' is not a DOM reference.\n", err)
|
||||
|
||||
def test_dom_task_ref(self):
|
||||
""" DOM reference to other task """
|
||||
code, out, err = self.t("_get 2.due")
|
||||
|
@ -187,8 +192,8 @@ class TestDOM(TestCase):
|
|||
|
||||
def test_dom_rc_missing(self):
|
||||
""" DOM rc.missing """
|
||||
code, out, err = self.t.runError("_get rc.missing")
|
||||
self.assertEqual(code, 1)
|
||||
code, out, err = self.t("_get rc.missing")
|
||||
self.assertEqual("\n", out)
|
||||
|
||||
def test_dom_attribute_missing(self):
|
||||
"""DOM 1.end (missing)"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue