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:
Paul Beckingham 2015-08-03 09:05:17 -04:00
parent ebecaf420e
commit 37bd07883b
11 changed files with 47 additions and 16 deletions

View file

@ -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;
}
////////////////////////////////////////////////////////////////////////////////