CLI2: Properly categorize FILTER, MODIFICATION, MISCELLANEOUS

- Now that CLI2::categorizeArgs is complete, all that remains is to make sure
  the individual commands comply.
This commit is contained in:
Paul Beckingham 2015-09-06 14:53:46 -04:00
parent d1fe1279ed
commit d60a2f9954
2 changed files with 73 additions and 24 deletions

View file

@ -908,10 +908,13 @@ void CLI2::categorizeArgs ()
if (a._lextype == Lexer::Type::separator)
continue;
// Record that the command has been found, it affects behavior.
if (a.hasTag ("CMD"))
{
afterCommand = true;
}
// Skip admin args.
else if (a.hasTag ("BINARY") ||
a.hasTag ("RC") ||
a.hasTag ("CONFIG"))
@ -919,43 +922,89 @@ void CLI2::categorizeArgs ()
// NOP.
}
// All MODIFICATION args appear after the command.
else if (cmd &&
cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous () &&
afterCommand)
{
a.tag ("MODIFICATION");
changes = true;
}
else if (cmd &&
cmd->accepts_miscellaneous () &&
! cmd->accepts_modifications () &&
(afterCommand ||
! cmd->accepts_filter ()))
{
a.tag ("MISCELLANEOUS");
changes = true;
}
else if (cmd &&
cmd->accepts_filter () &&
(! afterCommand ||
(! cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous ())))
{
a.tag ("FILTER");
changes = true;
}
// All combinations, with all 8 cases handled below.:
//
// -- -- -- Error: found an arg, but none expected
// -- -- Mi task [Mi] <cmd> [Mi]
// -- Mo -- task [Mo] <cmd> [Mo]
// -- Mo Mi Internally inconsistent
// Fi -- -- task [Fi] <cmd> [Fi]
// Fi -- Mi task [Fi] <cmd> [Mi]
// Fi Mo -- task [Fi] <cmd> [Mo]
// Fi Mo Mi Internally inconsistent
//
else if (cmd &&
! cmd->accepts_filter () &&
! cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous ())
{
// No commands were expected --> error.
throw format (STRING_PARSER_UNEXPECTED_ARG, command, a.attribute ("raw"));
}
else if (cmd &&
! cmd->accepts_filter () &&
! cmd->accepts_modifications () &&
cmd->accepts_miscellaneous ())
{
a.tag ("MISCELLANEOUS");
changes = true;
}
else if (cmd &&
! cmd->accepts_filter () &&
cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous ())
{
a.tag ("MODIFICATION");
changes = true;
}
else if (cmd &&
! cmd->accepts_filter () &&
cmd->accepts_modifications () &&
cmd->accepts_miscellaneous ())
{
// Error: internally inconsistent.
throw std::string (STRING_UNKNOWN_ERROR);
}
else if (cmd &&
cmd->accepts_filter () &&
! cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous ())
{
a.tag ("FILTER");
changes = true;
}
else if (cmd &&
cmd->accepts_filter () &&
! cmd->accepts_modifications () &&
cmd->accepts_miscellaneous ())
{
if (!afterCommand)
a.tag ("FILTER");
else
a.tag ("MISCELLANEOUS");
changes = true;
}
else if (cmd &&
cmd->accepts_filter () &&
cmd->accepts_modifications () &&
! cmd->accepts_miscellaneous ())
{
if (!afterCommand)
a.tag ("FILTER");
else
a.tag ("MODIFICATION");
changes = true;
}
else if (cmd &&
cmd->accepts_filter () &&
cmd->accepts_modifications () &&
cmd->accepts_miscellaneous ())
{
// Error: internally inconsistent.
throw std::string (STRING_UNKNOWN_ERROR);
}
}
if (changes &&

View file

@ -735,7 +735,7 @@
// Errors
// TODO Move each of these to appropriate section.
#define STRING_ERROR_PREFIX "Error: "
#define STRING_UNKNOWN_ERROR "Unknown error."
#define STRING_UNKNOWN_ERROR "Unknown error. Please report."
#define STRING_TRIVIAL_INPUT "You must specify a command or a task to modify."
#define STRING_ASSUME_INFO "No command specified - assuming 'information'."
#define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection."