- Converted ::safety from Parser to CLI.
- Updated unit tests to use the new template.
- Added tests to cover both values of rc.allow.empty.filter.
This commit is contained in:
Paul Beckingham 2014-10-26 09:02:51 -04:00
parent 87cd22792d
commit 74526ee564
2 changed files with 40 additions and 29 deletions

View file

@ -258,27 +258,29 @@ bool Filter::pendingOnly ()
// all tasks to be modified. This is usually not intended.
void Filter::safety ()
{
Tree* tree = context.parser.tree ();
std::vector <Tree*>::iterator i;
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
std::vector <A>::iterator a;
for (a = context.cli._args.begin (); a != context.cli._args.end (); ++a)
{
if ((*i)->hasTag ("WRITECMD"))
if (a->hasTag ("CMD"))
{
if (context.parser.getFilterExpression () == "")
if (a->hasTag ("WRITECMD"))
{
if (! context.config.getBoolean ("allow.empty.filter"))
throw std::string (STRING_TASK_SAFETY_ALLOW);
if (context.cli.getFilter () == "")
{
if (! context.config.getBoolean ("allow.empty.filter"))
throw std::string (STRING_TASK_SAFETY_ALLOW);
// If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE))
return;
// If user is willing to be asked, this can be avoided.
if (context.config.getBoolean ("confirmation") &&
confirm (STRING_TASK_SAFETY_VALVE))
return;
// Sounds the alarm.
throw std::string (STRING_TASK_SAFETY_FAIL);
// Sounds the alarm.
throw std::string (STRING_TASK_SAFETY_FAIL);
}
}
// Nothing to see here. Move along.
// CMD was found.
return;
}
}