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) if (a._lextype == Lexer::Type::separator)
continue; continue;
// Record that the command has been found, it affects behavior.
if (a.hasTag ("CMD")) if (a.hasTag ("CMD"))
{ {
afterCommand = true; afterCommand = true;
} }
// Skip admin args.
else if (a.hasTag ("BINARY") || else if (a.hasTag ("BINARY") ||
a.hasTag ("RC") || a.hasTag ("RC") ||
a.hasTag ("CONFIG")) a.hasTag ("CONFIG"))
@ -919,42 +922,88 @@ void CLI2::categorizeArgs ()
// NOP. // NOP.
} }
// All MODIFICATION args appear after the command. // 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 && else if (cmd &&
cmd->accepts_modifications () && ! cmd->accepts_filter () &&
! cmd->accepts_miscellaneous () &&
afterCommand)
{
a.tag ("MODIFICATION");
changes = true;
}
else if (cmd &&
cmd->accepts_miscellaneous () &&
! cmd->accepts_modifications () && ! cmd->accepts_modifications () &&
(afterCommand || ! cmd->accepts_miscellaneous ())
! cmd->accepts_filter ())) {
// 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"); a.tag ("MISCELLANEOUS");
changes = true; changes = true;
} }
else if (cmd &&
else if (cmd && ! cmd->accepts_filter () &&
cmd->accepts_filter () && cmd->accepts_modifications () &&
(! afterCommand || ! cmd->accepts_miscellaneous ())
(! 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"); a.tag ("FILTER");
changes = true; changes = true;
} }
else if (cmd &&
else if (cmd && cmd->accepts_filter () &&
! cmd->accepts_filter () &&
! cmd->accepts_modifications () && ! 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 ()) ! cmd->accepts_miscellaneous ())
{ {
throw format (STRING_PARSER_UNEXPECTED_ARG, command, a.attribute ("raw")); 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);
} }
} }

View file

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