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