Enhancement

- When a command is encountered on the command line, followed by an
  ID or UUID, the distance (in arguments) between the command and
  the sequence is measured in terms of arguments that are not rc: or
  rc. overrides.  It cannot exceed 1.  This helps disambiguate
  commands like 'task list Fedora 13', because the '13' is more than
  one argument away from 'list', and is therefore not an ID.
This commit is contained in:
Paul Beckingham 2011-07-11 00:54:01 -04:00
parent 21ad7a3d3f
commit 6009507209

View file

@ -286,6 +286,10 @@ void Arguments::categorize ()
bool found_something_after_sequence = false; bool found_something_after_sequence = false;
bool found_non_sequence = false; bool found_non_sequence = false;
// Track where the command is, if possible.
int command_pos = -1;
int distance_from_command = 0;
// Configurable support. // Configurable support.
bool enable_expressions = context.config.getBoolean ("expressions"); bool enable_expressions = context.config.getBoolean ("expressions");
bool enable_patterns = context.config.getBoolean ("patterns"); bool enable_patterns = context.config.getBoolean ("patterns");
@ -297,9 +301,10 @@ void Arguments::categorize ()
keywords.push_back (k->first); keywords.push_back (k->first);
// Now categorize every argument. // Now categorize every argument.
int counter = 0;
std::string ignored; std::string ignored;
std::vector <Triple>::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg, ++counter)
{ {
if (!terminated) if (!terminated)
{ {
@ -340,6 +345,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
command_pos = counter;
arg->_third = "command"; arg->_third = "command";
} }
@ -360,28 +367,30 @@ void Arguments::categorize ()
// <id>[-<id>][,...] // <id>[-<id>][,...]
else if (is_id (arg->_first)) else if (is_id (arg->_first))
{ {
if (!found_something_after_sequence) if (found_something_after_sequence ||
(command_pos != -1 && distance_from_command > 0))
{ {
found_sequence = true; arg->_third = "word";
arg->_third = "id";
} }
else else
{ {
arg->_third = "word"; found_sequence = true;
arg->_third = "id";
} }
} }
// <uuid>[,...] // <uuid>[,...]
else if (is_uuid (arg->_first)) else if (is_uuid (arg->_first))
{ {
if (!found_something_after_sequence) if (found_something_after_sequence ||
(command_pos != -1 && distance_from_command > 0))
{ {
found_sequence = true; arg->_third = "word";
arg->_third = "uuid";
} }
else else
{ {
arg->_third = "word"; found_sequence = true;
arg->_third = "uuid";
} }
} }
@ -392,6 +401,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "tag"; arg->_third = "tag";
} }
@ -402,6 +414,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "attmod"; arg->_third = "attmod";
} }
@ -412,6 +427,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "attr"; arg->_third = "attr";
} }
@ -422,6 +440,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "subst"; arg->_third = "subst";
} }
@ -432,6 +453,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "pattern"; arg->_third = "pattern";
} }
@ -442,6 +466,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "op"; arg->_third = "op";
} }
@ -452,6 +479,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "exp"; arg->_third = "exp";
} }
@ -462,6 +492,9 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1)
++distance_from_command;
arg->_third = "word"; arg->_third = "word";
} }
} }
@ -615,6 +648,7 @@ void Arguments::resolve_aliases ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// These are some delicate heuristics here. Tread lightly.
void Arguments::inject_defaults () void Arguments::inject_defaults ()
{ {
// Scan the arguments and detect what is present. // Scan the arguments and detect what is present.
@ -654,18 +688,20 @@ void Arguments::inject_defaults ()
else else
throw std::string (STRING_TRIVIAL_INPUT); throw std::string (STRING_TRIVIAL_INPUT);
} }
// Modify command.
if (found_other)
{
capture_first ("modify");
}
// Information command.
else else
{ {
context.header (STRING_ASSUME_INFO); // Modify command.
capture_first ("information"); if (found_other)
{
capture_first ("modify");
}
// Information command.
else
{
context.header (STRING_ASSUME_INFO);
capture_first ("information");
}
} }
} }
} }